301 Redirect "wildcard" question
-
I have been looking at the SEOmoz redirect guide for some advice but I can't seem to find the answer : http://www.seomoz.org/learn-seo/redirection
I have lots of URLs from a previous version of a site that look like the following:
etc etc.
I want to write a redirect so whenever a URL with the terms "-c-25.html" is requested it redirects to a specified page, regardless of what comes after the question mark.
These URLs were created by our previous ecommerce software. The 'c' is for category, and each page of the cateogry created a different URL. I want to do these so I can rediect all of these URLs to the appropraite new cateogry page in a single redirect.
Thanks for any help.
-
When I did a similar transition with hundreds of thousands of links. I created a database table with source and destination columns. Then a script that handles all 404 requests. If the requested link matches an entry in the source column, the user is sent a 301 to the matching destination entry. That allowed for easier maintenance than a huge htaccess file and the server load caused by te script should go down over time as 301 are saved and you contact site owners to update links. The other benefit is that you can do enhanced tracking to see what is request, found and not found and where those people came from.
-
An easy way is to use RedirectMatch, example:
RedirectMatch 301 /-c-25.html http://www.domain.com/new-category
Drop the above in a .htaccess file, test it works how you expect first
-
OK, If I make it the first redirect then the redirection works - regardless of what is written after the 'c-21.html'.
However the redirect is retaining the erroneous URL data after redirection. It is adding the '?blahblahblah" to the end of the new URL. I want it to dispose of this so all the redirects are routed to just one URL. How do I instruct it to not include this unwanted data in the new URL?
Thanks
-
Order matters in Rewrites. You will have to place that Rewrite Rule above the others.
-
I thought that may do it but still nothing. Maybe I am entering it wrong? Here is the code in .htaccess:
RewriteEngine On
RewriteBase /test/
RewriteRule ^index.php$ - [L
]RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /test/index.php [L]
RewriteRule ^-c-21.html(.*)$ http://www.mysitename.com/test/category/t-shirts/dolphin_tshirts [R=301,L
]
The redirect just doesn't happen.
EDIT: If I write a standard redirect : Redirect 301 /test/-c-21.html then it will redirect to the desired page but it will retain the ?blahblah and add it to the new URL. I want it to work like this but discard the ?blahblahblah after redirecting.
-
If you need these to be 301 redirects...
RewriteRule ^-c-25.html(.*)$ http://www.yoursite.com/dolphin_tshirts [R=301,L]
-
Just to calrify I need a URL that has
/-c-25.html?blahblahblah
to change to:
/dolphin_tshirts
Regardless of that is written in the blahblahblah part.
-
I think that would probably work for him, assuming that the category IDs remain the same.
-
Would something liek this work:
RewriteRule ^-c-(.).html(.)$ category/$1.html$2 [R,NC]
I've not tested it, nor do I claim to be an expert, but I think it will work for what you're tryign to acheive - e.g. -c-25.html becomes category/25.html
-
If your site is in PHP, you could simply add the code...
$targetURL = "http://www.sitename.com/whatever-page-you-what";
if(stristr($_SERVER['REQUEST_URI'],"-c-25.html")) {
header("HTTP/1.1 301 Moved Permanently"); header("Location: $targetURL");
}
?>
If you don't have access to PHP, you could add a line like this to your HTACCESS file...
RewriteCond %{THE_REQUEST} (c-25.html) [NC]
RewriteRule .* http://www.sitename.com/your-target-page [L,R=301]Someone might want to double check me on that rewriteRule above, though.
Got a burning SEO question?
Subscribe to Moz Pro to gain full access to Q&A, answer questions, and ask your own.
Browse Questions
Explore more categories
-
Moz Tools
Chat with the community about the Moz tools.
-
SEO Tactics
Discuss the SEO process with fellow marketers
-
Community
Discuss industry events, jobs, and news!
-
Digital Marketing
Chat about tactics outside of SEO
-
Research & Trends
Dive into research and trends in the search industry.
-
Support
Connect on product support and feature requests.
Related Questions
-
301 redirect with Magento; still Page authority 0 after 6 weeks
Hi Mozzers! In December '14 I have execute a 301 redirect in the 'old' page in the admin of my Magento store. Now I was surprised to see that the Page Authority is still 0 of the new page 6 weeks after the execution. should I have seen the update of the PA on the new page already after 6 weeks of time? If yes, then I assume that my Magento didn't execute this properly? Old url: http://hippemamashop.nl/mama/boeken/fotoalbum.html
Technical SEO | | aznventure
New page: you will be redirected to the new page after clicking the old page Mm4uBEl0 -
301 Redirect domain with penalty
Wondering if I could get a few views on this please... I have added an affiliate store to a domain I own, however I forgot to noindex the product pages which were duplicate content of the merchants. Despite a good deal of backlink building the site will not do much in the engines at all, doesn't even come up on the first few pages for it's own name! This suggests to me that I have a duplicate content penalty. Try as I may I cannot get it removed so am thinking of cloning the domain to a new domain, however, I do not want to lose the links I collected so I am planning on 301ing them. While I will not get all the link power moved over, I should at least get credit for some of them which will kick start the new domain. Can anyone forsee any potential issues with doing this? Is there a danger of 301ing a site with a penalty that the penalty would be carried over? I know there is no penalty on the links, no WMT warnings etc, it is the content causing the issue. Thanks, Carl
Technical SEO | | Grumpy_Carl0 -
Redirecting a questionable domain to a trusted domain
I have a question!
Technical SEO | | FDFPres
We have 2 domains operating within the same retail sector. One of them is for our bricks and mortar business and the other is a new brand we launched as a nationwide e-retailer. We aggressively built links for the new one and achieved some very good search positioning, where we remained for about 4 months until the google updates of the first half of this year started biting. The domain never received a warning from google or anything, but the links have clearly been devalued to a point where the domain is now virtually buried for the most competitive terms. However, the domain does still get around 100-200 visitors per day, and has a DA of 38. We're thinking about a reshuffle that would involve putting the products in to our brick and mortar business website, and redirecting the brand domain to the bricks and mortar domain. Thank you for reading this far! the question is then, is there a danger of the bricks and mortar domain being tarnished by this? as i said the brand domain hasn't had any notices of penalty from google but it has definitely been hit by updates.0 -
302 to 301 redirect confirmation
Hi guys, Fairly sure of the answer from what I've read so far, but I just wanted to doublecheck I have it right. Page A gets a significant amount of referring, followed traffic, and also ranks in Google. Page A uses a 302 redirect to Page B (on a completely different domain), which means that 0% of Page A's link juice is being passed on to Page B. If I were to change the 302 redirect to a 301 redirect, then the link juice passed on to Page A from the followed, referring traffic will be (mostly) passed on to Page B. Is that correct? Cheers, Jez
Technical SEO | | jez0000 -
Redirect question
I would like to redirect http://example.com/index.html to http://www.example.com/ Is the code below correct ? RewriteEngine on RewriteCond %{HTTP_HOST}^example.comRewriteRule (.*) http://www.example.com/$1 [R=301,L] RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index.html\ HTTP/ RewriteRule ^index.html$ http://www.example.com/ [R=301,L]
Technical SEO | | seoug_20050 -
Loss of search engine positions after 301 redirect - what went wrong?!?
Hi Guys After adhering to the On Page optimisation suggestions given by SEOmoz, we redirected some of old urls to new ones. We set 301 redirects from the old pages to new on a page by page basis but our search engine ranking subsequently fell off the radar and lost PR. We confirmed redirection with fiddler and it shows 301 permanent redirect on every page as expected. To manage redirection using a common code logic we executed following: In Http module, using “rewrite path” we route “all old page requests” to a page called “redirect.aspx? oldpagename =[oldpagename]”. This happens at server side. In redirect.aspx we are redirecting from old page to new page using 301 permanent redirect. In the browser, when old page is requested, it will 301 redirect to new page. In hope we and others can learn from our mistakes - what did we do wrong ?!? Thanks in advance. Dave - www.paysubsonline.com
Technical SEO | | Evo0 -
Should I use a "-", ":", or "|" in the title tag?
Out of habit, I've always put a "-" or dash to separate items in the title tag. However, I've noticed that more and more sites are using either a ":" or "|" in the title. Is there one that is better to use than the other?
Technical SEO | | beeneeb0