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 to do with old content after 301 redirect
 I'm going through all our blog and FAQ pages to see which ones are performing well and which ones are competing with one another. Basically doing an SEO content clean up. Is there any SEO benefit to keeping the page published vs trashing it after you apply a 301 redirect to a better performing page? Technical SEO | | LindsayE0
- 
		
		
		
		
		
		301 Redirect for multiple links
 I just relaunched my website and changed a permalink structure for several pages where only a subdirectory name changed. What 301 Redirect code do I use to redirect the following? I have dozens of these where I need to change just the directory name from "urban-living" to "urban", and want it to catch the following all in one redirect command. Here is an example of the structure that needs to change. Old Technical SEO | | shawnbeaird
 domain.com/urban-living (single page w/ content)
 domain.com/urban-living/tempe (single page w/ content)
 domain.com/urban-living/tempe/the-vale (single page w/ content) New
 domain.com/urban
 domain.com/urban/tempe
 domain.com/urban/tempe/the-vale0
- 
		
		
		
		
		
		Meta descriptions and h1 tags during a 301 redirect
 My employer is shifting to a new domain and i am in the midst of doing URL mapping. I realize that many of the meta descriptions and H1 tags are different on the new pages - is this a problem ? Thank you. Technical SEO | | ptapley0
- 
		
		
		
		
		
		301 Redirects in subfolders
 Hi, we're making our site into a static site but I would like to transfer the Google juice. Most of the links and database exist on subfolders though. Could I simply do 301 redirects on the subfolders and retain the value or does it have to be on the full domain? Technical SEO | | Therealmattyd0
- 
		
		
		
		
		
		A script to automatically write 301 redirect rules to htaccess?
 I was wondering if anyone could help provide some resources on how to automatically write 301 redirect rules to htaccess. Allow me to explain... I'm building a new website and the primary users are businesses. They have their own profile pages on the site. The URL is based off of their Company Name. In the event that they decided to change their name... reasons being, perhaps they mispelled it the first time, or they're removing LLC or adding Inc, I want to also change the URL and redirect the old URL to the new URL. Since the URL is based off of their Company Name, making a change to the company name would make a change to the URL. I know it doesn't have to work this way, but for our purpose this works best. In case the old URL had any links to it, I wanted to see if there was an way to automatically update an htaccess file with a 301 redirect from the old URL to the new one. Could anyone point me in the right direction of how to do this? Perhaps a sample script. I've done a lot of searches on Google and can't seem to find anything. e.g. Original: Technical SEO | | bimmer540
 Name: XYZ Widgets
 URL: website.com/xyz-widgets New - business changes their company name in their profile:
 Name: XYZ Widgets, Inc.
 URL: website.com/xyz-widgets-inc Upon the user saving the changes in their profile, I'd like to write a 301 redirect to an htaccess file:
 Redirect 301 /xyz-widgets http://www.website.com/xyz-widgets-inc I know how to manually write redirects and I've got a pretty smart web developer. We've just never triggered a script to automatically write to an htaccess file before. Is this possible? Any resources are appreciated. Any security risks? Thanks!0
- 
		
		
		
		
		
		Rel="external"
 Hi all, I got a link and its off a site and marked up with rel="external". Is this a followed or nofollowed link? Does it pass link juice? Thanks Technical SEO | | Sharer0
- 
		
		
		
		
		
		What is best practice for redirecting "secondary" domain names?
 For sites with multiple top-level domains that have been secured for a business or organization, I'm curious as to what is considered best practice for setting up 301 redirects for secondary domains. Is it best to do the 301 redirects at the registrar level, or the hosting level? So that .net, .biz, or other secondary domains funnel visitors to the correct primary/main domain name. I'm looking for the "best practice" answer and want to avoid duplicate content problems, or penalties from the search engines. I'm not trying to game the system with dozens of domain names, simply the handful of domains that are important to the client. I've seen some registrars recommend hosting secondary domains, and doing redirects from the hosting level (and they use meta refresh for "domain forwarding," which I want to avoid). It seems rather wasteful to set up hosting for a secondary domain and then 301 each URL. Technical SEO | | Scott-Thomas0
 
			
		 
			
		 
			
		 
			
		 
			
		 
					
				 
					
				 
					
				 
					
				 
					
				 
					
				 
					
				