Help Needed With .htaccess RewriteRule
-
Hello Fellow Mozzers,
I would really appreciate a little help as I have been banging my head against a wall for the last few hours trying to create a .htaccess RewriteRule.
I have around 300 URLs that I need to 301 redirect following a site re-build, they are in groups of similar urls but infortunately not broken down in to folders.
Here is an example of a few URLs:-
https://www.domain.co.uk/chamaecyparis-lawsoniana-ellwoodii_2.htm
https://www.domain.co.uk/chamaecyparis-lawsoniana-ellwoodii-200225cm-6670.htm
https://www.domain.co.uk/chamaecyparis-lawsoniana-ellwoodii.htm
https://www.domain.co.uk/chamaecyparis-lawsoniana-ellwoods-gold.htm
https://www.domain.co.uk/chamaecyparis-lawsoniana-lemon-queen.htm
https://www.domain.co.uk/chamaecyparis-lawsoniana-yvonne-200cm-66.htmAll of the above URLs need to redirect to a new URL:-
http://www.domain.co.uk/chamaecyparis-lawsoniana
Here is the RewriteRule that I currently have but it isn't working:-
RewriteEngine On
RewriteRule ^(.*)_chamaecyparis-lawsoniana$ https://www.domain.co.uk/chamaecyparis-lawsoniana [R=301,L]Anyone have any suggestions?
Thanks
Ade. -
Thanks Jaspal, works perfectly.
Yes we did meet at LinkLove and hopefully will do again at the next one as I now owe you a beer!
Much appreciated.
Ade. -
Hi Ade, didn't we meet up at LinkLove? Hope things are going well.
Try this:
RewriteRule ^chamaecyparis-lawsoniana-.+ https://www.domain.co.uk/chamaecyparis-lawsoniana [R=301,L]
The underscore was a problem as was the $ at the end
using -.+ at the end to avoid matching the target url
I tried that with regexr and it seems to work ok, not used it in an htaccess
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
-
Still Need to Write Title & Description Tag?
My SEO has advised me that Google has stopped using title and description tags for search results and as such, it is no longer necessary to write specific title and description tags. I see that Yoast seems to pull text to create these tags and sometimes it looks like it reflects the best elements of the content, sometimes it does not. Should I be asking our SEO team to write dedicated title and description tags or is it best practices to leave it to the Yoast plugin? My SEO is of the opinion that writing these tags is not a productive use of time as Google will serve results based on the user inquiry rather than the content on his tags. It sounds logical but it would be reassuring to receive further confirmation of this. Thoughts?"
Intermediate & Advanced SEO | | Kingalan1
Thanks, Alan0 -
Do I need to re-index the page after editing URL?
Hi, I had to edit some of the URLs. But, google is still showing my old URL in search results for certain keywords, which ofc get 404. By crawling with ScremingFrog it gets me 301 'page not found' and still giving old URLs. Why is that? And do I need to re-index pages with new URLs? Is 'fetch as Google' enough to do that or any other advice? Thanks a lot, hope the topic will help to someone else too. Dusan
Intermediate & Advanced SEO | | Chemometec0 -
Do I need to set Preferred domain when the non-www redirects to www version?
Hi mozzers, Not sure if I should setup preferred domain when the non www version redirects to the www version? if yes why? Thanks!
Intermediate & Advanced SEO | | Ideas-Money-Art0 -
Do we need breadcrumbs?
I found myself in a weird position today having to defend the use of breadcrumbs.... This is what I wrote.... From an SEO point of view it is best practice to have breadcrumbs as they are high up in the code and help the search engines crawling the site. Do you need a breadcrumb for SEO – Yes – as well as from a usability point of you view users can navigate a breadcrumb instead of hitting the back button. What would you have said?
Intermediate & Advanced SEO | | JohnW-UK0 -
Canonical Issue need hep
Hi Is my site has any issue with duplicate pages within the site , have i define my canonical tag properly , can any one advise please help. childrensfunkyfurniture.com
Intermediate & Advanced SEO | | conversiontactics0 -
Need some urgent Panda advice. Open discussion about recovering from the Panda algorithm.
I have a site that has been affected by Panda, and I think I have finally found the problem. When I created this site in the year 2006, I bought content without checking it. Recently, when I went through the site I found out that this content had many duplicates around the web. Not 100% exact, but close to. The first thing I did is ask my best writer to rewrite these topics, as they are a must on my site. This is a very experienced writer, and she will make the categories and subpages outstanding. Second thing I did was putting a NOINDEX, FOLLOW robots meta in place for the pages I determined being bad. They haven't been de-indexed yet. Another thing I recently did is separate other languages and move these over to other domains (with 301's redirecting the old locations to the new.) This means that the site now has a /en/ directory in the URL which is no longer used. With this in mind I was thinking to relocate the NEW content, and 301 the old (to preserve the juice for a while.) For example: http://www.mysite.com/en/this-is-a-pandalized-page/ 301 to http://www.mysite.com/this-is-the-rewritten-page/ The benefits of doing this are: decreasing the amounts of directories in the URL getting rid of pages that are possibly causing trouble getting fresh pages added to the site Now, the advice I am looking for is basically this: Do you agree with the above? Or don't you agree? If you don't, please be so kind to include a reason with your answer. If you do, and have any additional information, or would like to discuss, please go ahead 🙂 Thanks, Giorgio PS: Is it proven that Panda is now a running update? Or is it still periodically executed?
Intermediate & Advanced SEO | | VisualSense1 -
.htaccess - error404 redirect within a directory?
Hi, One of my clients has a CMS website offering Health and Safety training. When the courses have been run they automatically drop off of the system which is great for the front-end of the site but this leaves pile 404 errors for the URLs. I am trying to put a .htaccess redirect in place that will redirect back to the main category for that course i/e : http://www.domain.co.uk/courses/highways/6-NRSWA/27-nrswa-operative-sept-11.html will redirect to http://www.domain.co.uk/courses/highways/6-NRSWA I have spent a looooong time hitting google for a solution but can't seem to come up with anything. If at all possible I would also like to be able to post a php variable via the redirect url so that I can display a message on the category page saying that the course is no longer available be please select a different course. i/e: http://www.domain.co.uk/courses/highways/6-NRSWA?course=not-available Any help on this would be most gratefully received.
Intermediate & Advanced SEO | | AdeLewis0