How to redirect your domain to the Laravel /public folder using .htaccess

Many frameworks such as Laravel use a /public folder as the web root for security reasons.

If your hosting control panel does not allow you to change the Document Root, you can solve this using a small .htaccess rule.

This article shows you two options.

Option 1: Use an .htaccess rule

You can redirect all website traffic to the public folder.

Step 1

Open or create the file:

.htaccess

in the root of your website.

Example:

/public_html/.htaccess

Step 2

Add the following code:

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L]

What this does

This rule automatically loads all files from the public directory.

Example:

https://yourdomain.com/

will load:

https://yourdomain.com/public/

Your visitors will not see the /public path in the URL, but Laravel will work correctly.

Option 2: Ask Actiefhost to change the Document Root

The recommended solution is to change the Document Root of your domain to the public folder.

Example:

/home/username/domain/public

This is the best and most secure configuration for Laravel.

If you want us to configure this for your domain, please contact our support team.

Our support team will update the Document Root for you.

Was this article helpful?

Share this article