简体   繁体   中英

Laravel 5.2 .htaccess and 500 internal error

I have deployed my Laravel 5.2 project on Host.

The project works fine on local but gets me 500 Internal Server Error error when I deployed it on Host because of .htaccess file!

Here my .htaccess file :

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

PS:

Required PHP extensions for Laravel is installed and enabled. I also granted 775 permission to storage but nothing changed!

Any helps would be great appreciated.

Make sure you have permission to use .htaccess file in that folder by checking AllowOverride directive in you server config file. (usually httpd.ini ).

Full guide: https://httpd.apache.org/docs/2.4/mod/core.html#allowoverride

Check if mod_rewrite is installed and enabled in your php.ini file. Here is a basic explanation on how to install/enable mod_rewrite in apache: https://stackoverflow.com/a/5758551/3435728

Edit:

Make sure you have read permision on your .htaccess file

maybe not supported MultiViews options

<IfModule mod_rewrite.c>

RewriteEngine On

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

Try to follows below step as much you can do.

1. connect to hosting via SSH

2. install composer

3. in cpanel open Select PHP version and choose 5.4. (I also set phar extension)

4. install laravel: php composer.phar create-project laravel/laravel myproject --prefer-dist

5. copy everything from myproject/public to public_html

6. open public_html/index.php and set:

7. require __DIR__.'/../myproject/bootstrap/autoload.php';

8. $app = require_once __DIR__.'/../myproject/bootstrap/start.php';

for the 7 and 8 steps give the path where you source has so that file find that files

Hope this is works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM