Adam Jones
asked on
Htaccess 301 redirect with variables
I am having some problems. I switched over from one e-commerce system to another a while back and this changed the url structure of some of the pages. I was fine with this and set up some rewrite rules. Somehow this has stopped working and I am not sure why.
I need to change
I am using
But this is not working now and I don't have enough knowledge of htaccess redirects to work out what is wrong. I have been making changes and looking online but I feel like I am going in circles and this is very confusing.
Please, can anyone give me some advice?
I need to change
- /product/{Category-Name}/{
URL} to /{URL} - /ecategory/{Category-ID}/{
URL} to /{URL} - /manu/{URL} to /{URL}
- /news/{category-name}/{URL
} to /blog/{URL}
I am using
RewriteRule ^/?(product|ecategory)/([^\/]+)/(.+?)\$ /$3 [R=301,L]
RewriteRule ^/?(manu)/(.+?)\$ /$2 [R=301,L]
RewriteRule ^/?(news)/([^\/]+)/(.+?)\$ /blog/$2/$3 [R=301,L]
RewriteRule ^/?(newscategory)/([^\/]+)/(.+?)\$ /blog/$3 [R=301,L]
RewriteRule ^/?([0-9]+)/(.+?)\$ /$2 [R=301,L]
But this is not working now and I don't have enough knowledge of htaccess redirects to work out what is wrong. I have been making changes and looking online but I feel like I am going in circles and this is very confusing.
Please, can anyone give me some advice?
If you are using Apache 2.4, regexes and rewrites should be within double quotes. Under 2.2 and previous this was not enforced. The regexes and rewrites shown above would be workable (without regard to whether they are correct or not) under 2.2 but not under 2.4.
See the examples for 2.4 at the Apache project page below:
https://httpd.apache.org/docs/current/mod/mod_rewrite.html
See the examples for 2.4 at the Apache project page below:
https://httpd.apache.org/docs/current/mod/mod_rewrite.html
ASKER
Hi
Thanks for the advice but this does not work either. I am pretty sure this was not the problem because there are other rewrites that are not in quotes that are working fine.
I have edited the htaccess so these are the only these rewrites and it still does not work.
So, for example, I go to https://www.mysite.com/ecategory/10101/cat-name - I want it to go to https://www.mysite.com/cat-name but it does not change at the moment (keeping in mind that the number will change so it could be https://www.mysite.com/ecategory/999/cat-name for example) - Same with all the others apart from product one (RewriteRule "^product/(.*)$" "/$1" [R=301,NC,L]) but this does not have a second folder.
The forwarding I have for non-www to www, https and the product one is working fine
Thanks
Adam
Thanks for the advice but this does not work either. I am pretty sure this was not the problem because there are other rewrites that are not in quotes that are working fine.
I have edited the htaccess so these are the only these rewrites and it still does not work.
RewriteEngine On
RewriteBase /
RewriteRule "^/ecategory/([^\/]+)/(.+?)\$" "/$3" [R=301,L]
RewriteRule "^product/(.*)$" "/$1" [R=301,NC,L]
RewriteRule "^/?(manu)/(.+?)\$" "/$2" [R=301,L]
RewriteRule "^/?(news)/([^\/]+)/(.+?)\$" "/blog/$2/$3" [R=301,L]
RewriteRule "^/?(newscategory)/([^\/]+)/(.+?)\$" "/blog/$3" [R=301,L]
RewriteRule "^/?([0-9]+)/(.+?)\$" "/$2" [R=301,L]
So, for example, I go to https://www.mysite.com/ecategory/10101/cat-name - I want it to go to https://www.mysite.com/cat-name but it does not change at the moment (keeping in mind that the number will change so it could be https://www.mysite.com/ecategory/999/cat-name for example) - Same with all the others apart from product one (RewriteRule "^product/(.*)$" "/$1" [R=301,NC,L]) but this does not have a second folder.
The forwarding I have for non-www to www, https and the product one is working fine
Thanks
Adam
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This shows one way for accomplishing what your targeting...
Open in new window