Link to home
Start Free TrialLog in
Avatar of Adam Wassall
Adam Wassall

asked on

Permanent redirect with variables

I need some help - I am switching to a new system with my ecommerce website but this system has a new URL structure. I really want to be able to redirect the old pages to the new ones. I have too many pages to do it manually with 301 redirects so wanted to know if it would be possible to do with redirects with variables. If anyone can help me I will be in your debt.

Here is what I am trying to do (the stuff in {} are variables)

I need to change the product url from

/product/{Category-Name}/{URL}.html to /{URL}.html

I need the Category URL to change from

/ecategory/{Category-ID}/{URL}.html to /{URL}.html

and the manufacturers URL to change from

/manu/{URL}.html to /{URL}.html

So I think I will need to use the RewriteRule but I am not sure about the variables.

Any help will be very appreciated.
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Try:
RewriteEngine on
RewriteRule   "^/?(product|ecategory|manu)/([^\/]+)/(.+?)\.html)$"  "/$3.html"  [R=301,L]

Open in new window

Avatar of Adam Wassall
Adam Wassall

ASKER

Hi

This gives me an internal server error. I have tried it without the " and same.

Thanks
Can you post line from error log?
sure. Here it is

[Fri Jul 17 22:48:35.072132 2015] [core:alert] [pid 32062] [client 82.38.158.235:65201] /home/dwasep/public_html/.htaccess: RewriteRule: cannot compile regular expression '^/?(product|ecategory|manu)/([^\\/]+)/(.+?)\\.html)$'

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Parentheses dont match
And "redirect with variable" should be temporary.
Just to be clear, it appears that all of the original paths need to be rewritten like this:
FROM...                                TO...
/product/{Category-Name}/{URL}.html    /{URL}.html
/ecategory/{Category-ID}/{URL}.html    /{URL}.html
/manu/{URL}.html                       /{URL}.html

Open in new window

It looks like what you need to do is simply eliminate these components from the original paths?
/product/{Category-Name}
/ecategory/{Category-ID}
/manu

Open in new window

This would seem to imply that there will never be a collision on any subset of the existing /product, /ecategory or /manu paths, right?
Great that worked brilliantly. Thank you.