user3134976
user3134976

Reputation: 31

Existing rule redirect to new url rule

My old URL structure is like domain.com/product-name-etc-pid-001.html which I had the following htaccess code:

RewriteRule (.*)-pid-(.*)\.html$ p.php?n=$1&pid=$2

For my new structure the URLs are domain.com/products/product-name-etc/001

RewriteRule ^products/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ p.php?pid=$2 [NC,L]

Now I want all of the old URLs to be pointed to their new locations permanently.

   Redirect 301 /(.*)-pid-(.*)\.html$ ^compare/$1/$2/?$

I have been experimenting and come up with the above code, as expected it did not work and gave a 500 Internal Server Error.

Upvotes: 0

Views: 31

Answers (2)

user3134976
user3134976

Reputation: 31

Used old rule and made slight modification and come with the following solution:

RewriteRule ^(.*)-pid-(.*)\.html$ /compare/$1/$2 [L,NC,R=301]

Upvotes: 0

anubhava
anubhava

Reputation: 785481

You can use these rules:

RewriteRule ^([^-]+)-pid-([^.]+)\.html$ /products/$1/$2 [L,NC,R=301]

RewriteRule ^products/([\w-]+)/([\w-]+)/?$ /p.php?n=$1&pid=$2 [NC,L,QSA]

Upvotes: 1

Related Questions