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.
Adam WassallAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Open in new window

0
Adam WassallAuthor Commented:
Hi

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

Thanks
0
gheistCommented:
Can you post line from error log?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Adam WassallAuthor Commented:
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

0
hieloCommented:
My apologies.  I accidentally left a trailing close-parenthesis to the left of the $, leaving the regex unbalanced.  It should have been:
RewriteEngine on
RewriteRule   "^/?(product|ecategory|manu)/([^\/]+)/(.+?)\.html$"  "/$3.html"  [R=301,L]

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gheistCommented:
Parentheses dont match
And "redirect with variable" should be temporary.
0
Ray PaseurCommented:
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?
0
Adam WassallAuthor Commented:
Great that worked brilliantly. Thank you.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.