sasori Posted May 19, 2013 Share Posted May 19, 2013 (edited) 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 May 19, 2013 by sasori Quote Link to comment https://forums.phpfreaks.com/topic/278154-how-to-redirect-all-urls-to-a-different-url/ Share on other sites More sharing options...
kicken Posted May 19, 2013 Share Posted May 19, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/278154-how-to-redirect-all-urls-to-a-different-url/#findComment-1430912 Share on other sites More sharing options...
sasori Posted May 19, 2013 Author Share Posted May 19, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/278154-how-to-redirect-all-urls-to-a-different-url/#findComment-1430914 Share on other sites More sharing options...
jazzman1 Posted May 19, 2013 Share Posted May 19, 2013 (edited) Use the same logic - http://forums.phpfreaks.com/topic/277958-htaccess-re-writing-a-url-using-multiple-parts-of-the-original/ Edited May 19, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/278154-how-to-redirect-all-urls-to-a-different-url/#findComment-1430923 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.