Jump to content

how to redirect all URLs to a different URL?


sasori

Recommended Posts

e.g

I have a urls like in this format,


domain/buy-now/product title/productid

 

 

so here's one example

http://www.mydomain.com/buy-now/this-is-the-product-one/order/1234

Considering an online shop contains alot of products with different product title and product ID right? how am I going to redirect "all URLs from that format", into "this new URL" via htaccess ?

http://www.mydomain.com/buy-now/order/this-is-the-product-one/1234

the difference is, the word "order" got transferred beside the "buy-now"

what to do?

Use mod re-write. Depending on how complex the change(s) are you can either do it strictly w/ mod re-write or via an intermediary php script.

 

For the given example, something such as this should do the trick:

RewriteEngine On
RewriteRule ^/buy-now/(\w+)/order/(\d+)$ /buy-now/order/$1/$2 [R=301]
You may need to tweak the regex, I didn't test it at all. Once the regex is correct though, that will issue a permanent redirect for the old URL format to the new URL form.

Use mod re-write. Depending on how complex the change(s) are you can either do it strictly w/ mod re-write or via an intermediary php script.

 

For the given example, something such as this should do the trick:

RewriteEngine On
RewriteRule ^/buy-now/(\w+)/order/(\d+)$ /buy-now/order/$1/$2 [R=301]
You may need to tweak the regex, I didn't test it at all. Once the regex is correct though, that will issue a permanent redirect for the old URL format to the new URL form.

 

 

 

I tried this

 

 

RewriteRule ^/buy-now/^(.*)$/order/(\d+)$ /buy-now/order/$1/$2 [R=301]

 

still doesn't work at all

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.