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
- 
		
		
		
		
		
		301 redirects delay in picking up
 Hi I have been involved in the redesign/development of a website which has up until now had a lot of international traffic. On day of migration I uploaded all the 301 redirects to the website (wordpress) using Simple 301 redirect plugin. I tested a number of them and they appeared to be working. I also submitted the new sitemaps to Search Console. Since migration international traffic - particularly from countries such as india, Phillipines, Sri Lanka etc have significantly dropped off whereas the local traffic and some of the international traffic such as USA has remained fairly consistent. Looking at Analytics and entrances recently it appears as though search results are/were showing a number of pages with 404's (one in particular which received significant traffic and for which I had created a 301 redirection) - I have checked this page using the old url and it re-directs correctly for me and today asked a colleague in India to also check - he is getting the redirection fine. Does Google.in take a significantly longer time to pick these up in search results? Or am I missing something? Technical SEO | | musthavemarketing0
- 
		
		
		
		
		
		Does using data-href="" work more effectively than href="" rel="nofollow"?
 I've been looking at some bigger enterprise sites and noticed some of them used HTML like this: <a <="" span="">data-href="http://www.otherodmain.com/" class="nofollow" rel="nofollow" target="_blank"></a> <a <="" span="">Instead of a regular href="" Does using data-href and some javascript help with shaping internal links, rather than just using a strict nofollow?</a> Technical SEO | | JDatSB0
- 
		
		
		
		
		
		How do I add "noindex" or "nofollow" to a link in Wordpress
 It's been a while since I've SEOed a Wordpress site. How do I add "nofollow" or "noindex" to specific links? I highlight the anchor text in the text editor, I click the "link" button. I could have sworn that there used to be an option in the dialogue box that pops up. Technical SEO | | CsmBill0
- 
		
		
		
		
		
		"nofollow pages" or "duplicate content"?
 We have a huge site with lots of geographical-pages in this structure: domain.com/country/resort/hotel domain.com/country/resort/hotel/facts domain.com/country/resort/hotel/images domain.com/country/resort/hotel/excursions domain.com/country/resort/hotel/maps domain.com/country/resort/hotel/car-rental Problem is that the text on ie. /excursions is often exactly the same on .../alcudia/hotel-sea-club/excursion and .../alcudia/hotel-beach-club/excursion The two hotels offer the same excursions, and the intro text on the pages are the exact same throughout the entire site. This is also a problem on the /images and /car-rental pages. I think in most cases the only difference on these pages is the Title, description and H1. These pages do not attract a lot of visits through search-engines. But to avoid them being flagged as duplicate content (we have more than 4000 of these pages - /excursions, /maps, /car-rental, /images), do i add a nofollow-tag to these, do i block them in robots.txt or should i just leave them and live with them being flagged as duplicate content? Im waiting for our web-team to add a function to insert a geographical-name in the text, so i could add ie #HOTELNAME# in the text and thereby avoiding the duplicate text. Right now we have intros like: When you visit the hotel ... instead of: When you visit Alcudia Sea Club But untill the web-team has fixed these GEO-tags, what should i do? What would you do and why? Technical SEO | | alsvik0
- 
		
		
		
		
		
		301 redirects & merging two sites into one
 We have a client that has two sites that rank well for different searches in their market. The main pages ranking are things like advice articles and news pieces. For various reasons, they just want one site. I believe they need to duplicate the content from the outgoing site and place it on the main site, with a 301 redirect from each old page to each new one. What happens when they eventually want to redirect the entire domain? Would these smaller, internal redirects become obsolete, therefore removing any link value they once had? I am not sure how this works or if there is a best practice way to do this. Thanks Gareth Technical SEO | | Gmorgan0
- 
		
		
		
		
		
		How long should I keep 301 redirects?
 I have modified a the URL structure of a whole section of a website and used mod_rewrite 301 redirect to match the new structure. Now that was around 3 months ago and I was wondering how long should I keep this redirect for? As it is a new website I am quite sure that there are no links around with the old URL structure but still I can see the google bot trying from time to time to access the old URL structure. Shouldn't the google bot learn from this 301 redirect and not go anymore for the old URL? Technical SEO | | socialtowards0
- 
		
		
		
		
		
		Is it worth setting up 301 redirects from old products to new products?
 This year we are using a new supplier and they have provided us a product database of approx. 5k products. About 80% of these products were in our existing database but once we have installed the new database all the URLs will have changed. There is no quick way to match the old products with the new products so we would have to manually match all 5k products if we were were to setup 301 rules for the old products pointing to the new products. Of course this would take a lot of time. So the options are: 1. Is it worth putting in this effort to make the 301 rules? 2. Or are we okay just to delete the old product pages, let the SE see the 404 and just wait for it to index the new pages? 3. Or, as a compromise, should we 301 the old product page to the new category page as this is a lot quicker for us do do than redirecting to the new product page? Technical SEO | | indigoclothing0
- 
		
		
		
		
		
		301 Redirect with an Exact Domain name Match
 My Client had a site that ranked for a pretty competitive two word phrase, but for a variety of reasons had to transfer the site to a different domain name (with none of the previous keywords). We've 301'd everything just fine to the new site, but our traffic for that two word phrase, as well as related long tail traffic, is beginning to drop. Could the drop be related to something that we didn't do well in the transfer? Or is it due to the new domain name now not being an exact match? Sitenote question: Our Google Analytics is still set up for the former domain name and shows data just fine. Is there any reason to switch GA to the new domain? What are the pros/cons? Much thanks in advance! Technical SEO | | TrevorMcKendrick0
 
			
		 
			
		 
			
		 
			
		 
			
		 
					
				 
					
				 
					
				 
					
				 
					
				 
					
				 
					
				