Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel htaccess issue

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)

like image 232
Fraser Avatar asked Apr 11 '13 10:04

Fraser


People also ask

Does Laravel use htaccess?

The framework ships with a public/. htaccess file that is used to allow URLs without index. php . If you use Apache to serve your Laravel application, be sure to enable the mod_rewrite module.

Where is htaccess in Laravel?

htaccess file for redirecting to Laravel's public folder. In Laravel the path for serving your web page is in the /public folder. By default after installing Laravel and navigating in a browser to the URL you will see a directory listing of all the Laravel files.

What is .htaccess file in PHP?

htaccess (Hypertext Access) file is an Apache distributed server configuration file. You can use the . htaccess file to set server configurations for a specific directory. This directory can be the root directory of your website or another subdirectory where the .


1 Answers

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>
like image 57
RamiroRS Avatar answered Sep 29 '22 10:09

RamiroRS