Laravel htaccess issue

12,886

Use at same level of /public

This way first redirect to public

RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]

And inside /public

then, you handle index.php

<IfModule mod_rewrite.c>
    Options +FollowSymLinks
    RewriteEngine On
</IfModule>


<IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Share:
12,886
Fraser
Author by

Fraser

UK Web Developer. Co host of Three Devs and a Maybe www.threedevsandamaybe.com

Updated on June 28, 2022

Comments

  • Fraser
    Fraser almost 2 years

    I'm trying to set a site live. The site works perfectly fine on a live dev server which we've been using to show the site to the client. Here is the htaccess from the live dev (works fine):

    <IfModule mod_rewrite.c>
        Options +FollowSymlinks
        RewriteEngine On
    
        #RewriteCond %{HTTPS} !=on
        #RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
        #RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    
        # Rewrite to 'public' folder
        RewriteCond %{HTTP_HOST} ^livedev.domain.com$
        RewriteCond %{REQUEST_URI} !public/
        RewriteRule (.*) public/$1 [L]
    </IfModule>
    AuthType Basic
    AuthName "dev16"
    AuthUserFile "/home/site/.htpasswds/public_html/passwd"
    require valid-user
    

    And here's the .htaccess from the live site:

    <IfModule mod_rewrite.c>
        Options +FollowSymlinks
        RewriteEngine On
    
        #RewriteCond %{HTTPS} !=on
        #RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
        #RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    
        # Rewrite to 'public' folder
        RewriteCond %{HTTP_HOST} ^livesite.co.uk$
        RewriteCond %{REQUEST_URI} !public/
        RewriteRule (.*) public/$1 [L]
    </IfModule>
    

    The 2 are identical except for the HTTP_HOST and the removal of the authentication.

    It gives me a generic "Internal Server Error".

    I have tried deleting the contents of .htaccess which just gives me page not found so the issue definitely lies in .htaccess.

    A total .htaccess virgin, what steps can I take to find the cause of the issue?

    Thanks

    (It's Laravel 3.2.13)

  • Sanket Sahu
    Sanket Sahu over 10 years
    Adding a slash before index.php worked for me. RewriteRule ^(.*)$ /index.php/$1 [L]
  • Nebster
    Nebster almost 6 years
    Can you also add forcing of HTTPS to your solution please?