Forum Moderators: phranque
I use .htaccess to rewrite my URL's
eg
RewriteEngine On
RewriteRule -Jewellery-([a-z,A-Z,0-9,_]*)\.html /index.php?m=productDetail&p=$1
This finds any product which ends with "-jewellery-100.html", the number 100 can be any number and is my product ID. This works fine, only problem is i have renamed a page and need to do a 301 to the new page, so i now have.
#REDIRECTS -------
redirectpermanent /test/OLD-PAGE-Jewellery-100.html http://www.example.com/MY-NEW-PRODUCT-Jewellery-100.html
#-----------------
RewriteEngine On
RewriteRule -Jewellery-([a-z,A-Z,0-9,_]*)\.html /index.php?m=productDetail&p=$1
This then redirects, but because of the rewrite rule below it passes through a querystring, like so.
http://www.example.com/MY-NEW-PRODUCT-Jewellery-100.html?m=productDetail&p=100
I need to not have the querystring added by the rewrite, so i though something like
RewriteRule ([^OLD\-PAGE]+)-Jewellery-([a-z,A-Z,0-9,_]*)\.html /index.php?m=productDetail&p=$1
But i cannot get it to work as i would like - Someways it redirects but then doesnt recognise the rewrite rule so pages arent found. I have tried a variety of ways and different expressions - but they arent my strong point.
Please can someone help - i am pulling my hair out....
Thanks
Ally
The regular-expressions pattern in your second RewriteRule is (sorry) unrecognizable...
Second, do not mix mod_rewrite and mod_alias directives (such as "RedirectPermanent") unless you know that the URLs to be handled by the two directives are mutually-exclusive and will never interact. In your case here, that is not true -- We can be sure that they will interact! So use mod_rewrite for both functions, and put the external redirect first in order to avoid exposing your query string.
Third, bear in mind that we are doing two very different things here: We are externally redirecting an old URL, and we are internally rewriting static URLs to a dynamic script path. An external redirect informs and requires the cooperation of the client (browser or search engine robot), while an internal rewrite happens completely inside the server and is not (normally) visible to the world.
All-in all, I think you'll be much happier with these two rules in this order:
RewriteRule OLD-PAGE-Jewellery-100\.html$ http://www.example.com/MY-NEW-PRODUCT-Jewellery-100.html [R=301,L]
RewriteRule -Jewellery-([A-Za-z0-9_]+)\.html$ /index.php?m=productDetail&p=$1 [L]
Jim
I am pretty new to using regex and modrewrite so sorry if my first post was well off the mark - i have been using the same regex to pass variables using modrewrite for a couple of months now and this is the first time i have become stuck with it.
Thanks alot for your help and i will deffinitely do some reading up on the regex stuff in the forum library.
Ally