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?

Edited by sasori
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.