Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

TimeSocks's avatar

301 redirects for new site

I have just switched my site over to a shiny new one made with Laravel 5. Now I need to redirect the old URLs indexed by Google to the new ones.

The old URLs were in the format:

www.mysite.com/products/product.php?product_id=1

The new ones are in the format:

www.mysite.com/products/nice-product-slug

I've tried adding a 301 redirect in my .htaccess file using my host's Cpanel, but when I hit the old URL, the browser redirects to:

http://www.mysite.com/index.php?product_id=1

Is there something Laravel-specific I need to do? I've also read that editing the httpd.conf file may be a better solution. Any ideas very much appreciated.

0 likes
3 replies
bashy's avatar
bashy
Best Answer
Level 65

Redirects on Apache don't allow you to do direct ones from query strings to a URL. You have to do something like this;

RewriteCond %{QUERY_STRING} product_id=12$ 
RewriteRule (.*) /products/nice-product-slug/? [R=301,L] 

not tested

Please or to participate in this conversation.