Skip to content
Advertisement

Laravel Shared Hosting .htaccess

I am trying to deploy a Laravel project onto a share hosting, I’ve managed to get most of the hard work done but I cannot strip off the /public directory without a Forbidden issue.

The website works and shows same pages for these links

  • www.mywebsite.com/test/index.php
  • www.mywebsite.com/test/public/

But without the /index.php It returns ->

Forbidden

You don't have permission to access /test/ on this server. 

Currently my .htaccess looks like the following.

<IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ public/index.php [L]

</IfModule>

Any ideas?

Advertisement

Answer

Try this rule in test/.htaccess:

DirectoryIndex index.php
<IfModule mod_rewrite.c>

    RewriteEngine On
    RewriteBase /test/

    RewriteRule ^$ public/index.php [L]

    RewriteRule ^((?!public/).*)$ public/$1 [L,NC]

</IfModule>
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement