.htaccess Redirects In Laravel And On Forge

When migrating an old project to a new, Laravel based project, we would need to redirect (301 Header) old routes to new routes, e.g.

/index.php?page=shop ==> /shop
/index.php?category=abc&product_id=123 ==> /abc/item-123

For this, we've prepared a proper .htaccess file that works perfectly on the old project. However when we deploy the new project and change the domain DNS, the htaccess also needs to be in the new folder.

In Laravel, we do have /public/.htaccess, however, adding our .htaccess pieces won't work together with Laravel Forge. It is a simple .htaccess file that looks like:

<IfModule mod_rewrite.c>
# Enable Rewrite Engine
RewriteEngine On
RewriteBase /

# index.php?page=user&sub_page=settings
RewriteCond %{QUERY_STRING} ^page=user&sub_page=settings$
RewriteRule ^index\.php$  /users/notifications/permissions/edit [R=301,NC,L,QSD]

(... and so on)

So now we are wondering: how can we make it work, that it will forward old routes to the new routes in the same project based on Laravel?



Laravel Forge uses an nginx.conf file (which you can configure in forge) instead of the .htaccess file.

You can use the nginx reference to re-create your settings: You should look at the sections: location and redirect.

Hope This Helps!