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.
Apache Web ServerPHPHTMLScripting LanguagesWeb Development

Avatar of undefined
Last Comment
Adam Wassall
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
Avatar of gheist
gheist
Flag of Belgium image

Can you post line from error log?
Avatar of Adam Wassall
Adam Wassall

ASKER

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

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of gheist
gheist
Flag of Belgium image

Parentheses dont match
And "redirect with variable" should be temporary.
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

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?
Avatar of Adam Wassall
Adam Wassall

ASKER

Great that worked brilliantly. Thank you.
PHP
PHP

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

125K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo