Moz Q&A is closed.
After more than 13 years, and tens of thousands of questions, Moz Q&A closed on 12th December 2024. Whilst we’re not completely removing the content - many posts will still be possible to view - we have locked both new posts and new replies. More details here.
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. 
Browse Questions
Explore more categories
- 
		
		Moz ToolsChat with the community about the Moz tools. 
- 
		
		SEO TacticsDiscuss the SEO process with fellow marketers 
- 
		
		CommunityDiscuss industry events, jobs, and news! 
- 
		
		Digital MarketingChat about tactics outside of SEO 
- 
		
		Research & TrendsDive into research and trends in the search industry. 
- 
		
		SupportConnect on product support and feature requests. 
Related Questions
- 
		
		
		
		
		
		Delete old blog posts after 301 redirects to new pages?
 Hi Moz Community, I've recently created several new pages on my site using much of the same copy from blog posts on the same topics (we did this for design flexibility and a few other reasons). The blogs and pages aren't exactly identical, as the new pages have much more content, but I don't think there's a point to having both and I don't want to have duplicate content, so we've used 301 redirects from the old blog posts to the new pages of the same topic. My question is: can I go ahead and delete the old blog posts? (Or would there be any reasons I shouldn't delete them?) I'm guessing with the 301 redirects, all will be well in the world and I can just delete the old posts, but I wanted to triple check to make sure. Thanks so much for your feedback, I really appreciate it! Technical SEO | | TaraLP1
- 
		
		
		
		
		
		What is the difference between "Referring Pages" and "Total Backlinks" [on Ahrefs]?
 I always thought they were essentially the same thing myself but appears there may be a difference? Any one care to help me out? Cheers! Technical SEO | | Webrevolve0
- 
		
		
		
		
		
		Creating a CSV file for uploading 301 redirect URL map
 Hi if i'm bulk uploading 301 redirects whats needed to create a csv file? is it just a case of creating an excel spreadsheet & have the old urls in column A and new urls in column B and then just convert to csv and upload ? or do i need to put in other details or paremeters etc etc ? Cheers Dan Technical SEO | | Dan-Lawrence0
- 
		
		
		
		
		
		Changing title tags, do we need 301 redirects
 I found many duplicate title tags and I'm in the process of changing it Do I need 301 redirects in place when I switch it? I am only changing the title tag. Also, we are switching over to a new site very soon, I am worried that we might be using too many 301 redirect "hops" because we are doing a lot of optimization as well. (video from matt cutts describing 301 redirects and hops: http://www.youtube.com/watch?v=r1lVPrYoBkA. Does anyone have any experience in doing too many redirect hops that it affected your rankings? Any good ideas to avoid this? Technical SEO | | EcomLkwd0
- 
		
		
		
		
		
		Switching from a .org to .io (301 domain redirect)
 I'm considering switching my main site from a .org to .io address; the .org is an exact match domain which helped to kickstart it a few years ago and now has about 50% repeat visitors, but was thrown off the Apple affiliation program for trademark infringement. I've found and purchased a nice (non-infringing) .io domain, and I've read the advice here on how to properly 301 the old domain; but my question is - does it matter that it's .io? Is this going to significantly hurt my rankings, even when everything has been 301'd properly? Another thought I had is that I may actually come out better off in the long run, what with Google penalties being applied to exact match domains. Is this a ranking suicide? If so, I'm tempted to leave it as is; even without the affiliation, it's making a good amount every month in ad fees that I don't want to disrupt. Thanks all! Technical SEO | | w0lfiesmithUK0
- 
		
		
		
		
		
		301 Redirect on a PDF, DOCX files?
 Hi, I have to rename many pdf and docx files. How can I implement 301 redirect on them as they are linked from 'n' number of places? Regards, Shailendra Sial Technical SEO | | IM_Learner1
- 
		
		
		
		
		
		Delete 301 redirected pages from server after redirect is in place?
 Should I remove the redirected old pages from my site after the redirects are in place? Google is hating the redirects and we have tanked. I did over 50 redirects this week, consolidating content and making one great page our of 3-10 pages with very little content per page. But the old pages are still visible to google's bot. Also, I have not put a rel canonical to itself on the new pages. Is that necessary? Thanks! Jean Technical SEO | | JeanYates0
- 
		
		
		
		
		
		301 Redirect vs Domain Alias
 We have hundreds of domains which are either alternate spelling of our primary domain or close keyword names we didn't want our competitor to get before us. The primary domain is running on a dedicated Windows server running IIS6 and set to a static IP. Since it is a static IP and not using host headers any domain pointed to the static IP will immediately show the contents of the site, however the domain will be whatever was typed. Which could be the primary domain or an alias. Two concerns. First, is it possible that Google would penalize us for the alias domains or dilute our primary domain "juice"? Second, we need to properly track traffic from the alias domains. We could make unique content for those performing well and sell or let expire those that are sending no traffic. It's not my goal to use the alias domains to artificially pump up our primary domain. We have them for spelling errors and direct traffic. What is the best practice for handling one or both of these issues? Technical SEO | | briankb0
 
			
		 
			
		 
			
		 
			
		 
			
		 
					
				 
					
				 
					
				 
					
				 
					
				 
					
				 
					
				