How to do a 301 redirect for url's with this structure?
-
In an effort to clean up my url's I'm trying to shorten them by using a 301 redirect in my .htaccess file. How would I set up a rule to grab all urls with a specific structure to a new shorter url examples:
http://www.yakangler.com/articles/reviews/other-reviews/item/article-title
So in the example above dynamically redirect all url's with /articles/reviews/other-reviews/item/ in it to /reviews/ so
http://www.yakangler.com/articles/reviews/boat-reviews/item/1550-review-nucanoe-frontier
http://www.yakangler.com/articles/reviews/other-reviews/item/1551-review-spyderco-salt
would be...
http://www.yakangler.com/reviews/1550-review-nucanoe-frontier
http://www.yakangler.com/reviews/1551-review-spyderco-salt
http://www.yakangler.com/reviews/1524-slayer-inc-sinister-swim-tail
with one 301 redirect rule in my .htaccess file.
-
You can do this via RedirectMatch statements. There is an example of different match types you could use here. Basically, you create a pattern and then the code is smart enough to redirect based on that pattern.
Your redirect might look something like this though you might want to adjust the pattern match the directory in between /reviews/ and /item/. Mine is just a basic alphanumeric catch all.
RedirectMatch 301 ^/articles/reviews/([-A-z0-9]+)/item/(.*)$ http://clients.qwconsulting.com/reviews/$1
I hope that helps.
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
-
After 301 redirect
hello i do after 301 redirect from old domain to new since 3 month ago my qa : should i replace the backlinks links to new doamin Or the he backlinks in the old link will works
Intermediate & Advanced SEO | | cristophare790 -
301 Redirects to relative URLs not absolute a problem?
Hi we recently did a migration and a lot of content changed locations see: https://d.pr/i/RvqI81 Basically, the 301 goes to the correct location but its a relative URL (as you can see from the screenshot) rather than absolute URL. Do you think this is a high priority issue from an SEO standpoint, should we get the developer to change the redirects to absolute? Cheers.
Intermediate & Advanced SEO | | cathywix0 -
Do I need 301's if I use HSTS in HTTP to HTTPS migration?
Just wondering if this was strong enough signal to search engines that we don't need to write a 301 rule in .htaccess.
Intermediate & Advanced SEO | | KevinBudzynski0 -
A client rebranded a few years ago and doesn't want to be associated with it's old brand name. He wishes not to appear when the old brand is searched in Google, is there something we can do?
The problem is there was redirection between the old branded site and the new one, and now when you type in the name of the old brand, the new one comes up. I have desperately tried to convince this client there is nothing we can do about it, dozens of news articles crop up with the two brands together as this was a hot topic a few years ago, but just in case I missed something I thought I'd ask the community of experts here on Moz. An example for this would be Tyco Healthcare that became covidien in 2007. When you type tyco healthcare, covidien crops up here and there. Any ideas? Thanks!
Intermediate & Advanced SEO | | Netsociety0 -
301 Redirection
Hi there guys, I have a question about redirection. My boss has just bought a new domain name and he wants it to redirect to our current site when looking for specific products. www.example.com is our current website www.productname.com is the new domain So the new domain would be redirected to example.com. Would that be considered against Google Policies? Thanks
Intermediate & Advanced SEO | | PremioOscar0 -
Will Canonical tag on parameter URLs remove those URL's from Index, and preserve link juice?
My website has 43,000 pages indexed by Google. Almost all of these pages are URLs that have parameters in them, creating duplicate content. I have external links pointing to those URLs that have parameters in them. If I add the canonical tag to these parameter URLs, will that remove those pages from the Google index, or do I need to do something more to remove those pages from the index? Ex: www.website.com/boats/show/tuna-fishing/?TID=shkfsvdi_dc%ficol (has link pointing here)
Intermediate & Advanced SEO | | partnerf
www.website.com/boats/show/tuna-fishing/ (canonical URL) Thanks for your help. Rob0 -
Multiple 301 Redirects on the same domain name
Hi, I'd appreciate some advice ont he below. I have a website, say www.site.co.uk that has just been redesigned using a new CMS. Previously it had URLs in the format /article.php?id=123, the new site has more friendly urls in the format /articles/article-slug. I have been able to import the old articles into my CMS using the same article IDs and I have created a unique slug for each post. So now in my database, I have the article id (from the querystring) and a slug. However, I have hundreds of old URLs indexed by Google in the format /article.php?id=123 and need to redirect these. My plan was to do the following. 301 Redirect /article.php?id=123 to an intermediate page, in this case /redirect/123. On this intermediate page I would do a database lookup for the article slug, based on the ID from the querystring, create a new URL and perform a second 301 redirect to my new URL E.g. /articles/article-slug-from-database. Whilst this works and keeps the site usable for visitors the two 301 redirects do worry me, as I don;t want Google indexing lots of /redirect/[article id] urls. The other solution is to generate hundreds of htaccess redirect rules that map old url to the new url. The first solution is much cleaner, but the two 301's worry me. Will Google work this out on it's own, is there a better way? Any advice is much appreciated. Cheers Rob
Intermediate & Advanced SEO | | AmyCrompton1 -
What's the best SEO practice for having dynamic content on the same URL?
Let's use this example... www.miniclip.com and there's a function to log in... If you're logged in and a cookie checks that you're logged in and you're on page, let's say, www.miniclip.com/racing-games however the banners being displayed would have more call to action and offers on the page when a user is not logged in to entice them to sign up but the URL would still be www.miniclip.com/racing-games if and if not logged in, what would be the best URL practice for this? just do it?
Intermediate & Advanced SEO | | AdiRste0