Jump to content

[SOLVED] Site Migrate Old Urls to New Urls - issue with rewriting


Recommended Posts





We are migrating one of our sites from 1.5 to 1.6.


We have changed some of the categories and products within these categories, so some product-ids and category-id are different. So that we don't lose any of our SEO ranking I am going to rewrite all the old URL links for products to new ones within the .htaccess file. However I'm having a problem that hopefully someone can help me with. The following line in my .htaccess file I think should work:


RewriteRule ^old-category/262-product-test.html$  new-category/254-product-test.html [R=301,NC]


The product-id is 262 on the old site, but on the new site it's 254. Using this rule and typing in the url:


- old-category/262-product-test.html


I would expect it to reroute to url - new-category/254-product-test.html.


However what actually happens is that the url is redirected to new-category/262-different-product.html. The same product-id, but a different product.


Is my rewrite rule wrong (this could be a tongue-twister!!!), or is there something else I have to do in my .htaccess file.


Note: I have placed this rule at the bottom of the .htaccess file outwith the comment lines.


Thank you for any help.




Edited by prestatent (see edit history)

Share this post

Link to post
Share on other sites

You should end your rewrites with L flag, and also if you keep getting more problems i'm sure people can help if you post whole rewrite statements block.


RewriteRule ^old-category/262-product-test.html$  new-category/254-product-test.html [L,R=301,NC]
RewriteRule ^old-category/262-product-test\.html$  new-category/254-product-test.html [L,R=301,NC]
P.S: If it's your last rule, you need to check if no other rule intercepts beforehand. Edited by blackarma (see edit history)

Share this post

Link to post
Share on other sites

Thanks Mickeyboy & Blackarma. Appreciate your help on this.


I've placed this code at the start of the file, outwith the stuff that would get overwritten by PS. I'm running this on localhost at the moment. This is the whole block.


RewriteCond %{HTTP_HOST} ^localhost$

RewriteRule ^old-category/262-product-test.html$  http://localhost/new-category/254-product-test.html [R=301,NC,L]


The good news is that the above statements work. We run a multi-language site (6 languages), and I notice that if the language is appended to the url before the category the original issue still occurs. Any idea why this would be? eg. typing this into the browser works:




but this




reroutes to gb/new-category/262-different-product.html. The same product-id, but a different product which was the original issue.


So, I've now worked out that if I put the language in the old url it will work correctly, but as I have 6 languages on the site, do I then have to have 6 reroutes for each product?



I'm sure there must be a way around this, but as our products are all indexed with the language in the url, I'll have to get it working

Share this post

Link to post
Share on other sites

You would need to capture 2 of first symbols, then use it in redirect.


Are language parameter always present in url?
If so then you can do something like:

^([a-z]{2})/old-category/262-product.html$ $1/new-product/272-product.html [R=301,NC,L]

If not you will need to make non greedy slash capture also

Too bad i have no servers on apache so it's hard to guess like that from my head.

  • Like 1

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More