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
-
Is 301 redirect the only way when using Vanity URLs?
We have been using vanity urls for some of our pages. Mostly the pages that have a vanity URL have a long URL length. But now the problem is, the vanity URL is getting displayed on the search engine when the particular keyword related to the page is entered. I checked the google search console, the vanity URL is indexed and the original URL remains unindexed. What should I do? Is adding 301 redirect to the vanity URLs are solution? Since some of vanity URLs are not redirecting to the original. Some of the original pages are not getting traffic. Also, can using canonical tag help?
Technical SEO | | tejasbansode0 -
HTacess 301 redirect with special characters
Hello moz community ! I would to make a special 301 redirection through my htaccess file. I am a total noob concerning regexp and 301 redirection. I would like to redirect(301) this url : http://www.legipermis.com/stages-points/">http://www.legipermis.com/stages-points/</a></p>; yes yes it's in the index of google, this strange url includes the last ; to http://www.legipermis.com/stages-points/ I have already include a canonical tag by security, i would like to remove url with a 301 redirection and by remove this url through GWT (but the removal tool can't "eat' this kind of URL) Please consider the fact that i am not an expert about 301 redirections and regexps. No 301 redirect generator works properly for such a strange URL (which triggers content duplication corrected anyway with canonical tag). Thanks for your help.
Technical SEO | | LegiPermis0 -
Maintaining Link Value Of Old URLS With 301 Redirects
Large ecommerce site that has been around for a long time (15+ years.) During that time technology has changed a lot and we are running into issues maintaining 301 redirects for very old urls. For example we have a good amount of links to product and category pages. Some of the old links are to products that still exist and will exist for many years to come.(of note little to no traffic comes via these links. Most of them are close to 9 years old so they are buried deep within articles, forums, or websites) However as we make changes to the site and URL structure these old urls are taking up more resources to continue to maintain 301 redirects. I am Leary of no longer supporting them because I do not want it to impact rankings however there is concern on how much development time and technology resources it takes to continue to support as time goes on. Does anyone have experience handling redirects 3 or 4 url structures old? Looking for insight from someone who has crossed this bridge before.
Technical SEO | | RMATVMC0 -
Why can't I redirect 302 errors to 301's?
I've been advised by IT that due to the structure of our website (they don't use sub-folders) it's not possible to change 302's to 301's. Is this correct, or am I being fobbed off?
Technical SEO | | lindsaytuerena0 -
Webmaster tools doesn't pick up 301 redirect
I had a few hundred URLs that died on my site. Google Webmaster Tools notified me about the increase in 404 errors. I fixed all of them by 301 redirecting them to the most relevant page and did multiple header checks to ensure that the 301 has been implemented correctly. Now a few weeks later, Google is giving me the exact same message in Google Webmaster Tools but they are all still 301 redirected. WTF?
Technical SEO | | DROIDSTERS0 -
Permanent 301 redirects vs canonical urls?
Im moving a website that was .php to wordpress with a few static HTML pages. Which is better use permanent 301 redirects and delte the old pages, leave the old pages and use canonical urls and 301 redirects or something else?
Technical SEO | | senith0 -
301 Redirects
Hello, I have a problem with my website. I have a page on my website http://www.ensorbuilding.com/page.php/aboutus but if i type in www.ensorbuilding.com/page.php/aboutus/f8e45e9d9df6140bb5a7ff1173e8d828 or www.ensorbuilding.com/page.php/aboutus/0f0eea5e9ab0a3e8d91fad8fc0d3ce9c it still displays the about us page. Google is seeing this as duplicate content so what I would want to do is 301 redirect anything after www.ensorbuilding.com/page.php/aboutus . How could I implement a 301 redirect in this way?
Technical SEO | | danielmckay70 -
Should I move x-cart installation or 301 redirect?
We have an existing e-commerce site built on x-cart. The default store location is www.site.com/store. The domain root however is just a static HTML page (currently using mainly graphics) and a nav menu. What would be a better option: 1. Move the install location to the root directory and get rid of the static HTML page. We would have to manually 301 redirect all the old pages to the new location. Not sure if there are negative implications with that. 2. Just optimize the HTML landing page? Seems like it is better to have products and categories as close to the root domain as possible... 3. 301 redirect the domain to www.site.com/store/ and optimize the homepage within the store. This option means we dont have to worry about 2000 redirects or the hassle of moving the store. Anyone had any experience with this and suggestions?
Technical SEO | | BlinkWeb0