Laravel Forcing HTTPS with Mod Rewrite

2019-06-03 02:22发布

I have a site running Laravel 3 which needs to force https using the following rewrite rule in apache config:

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

This forces https correctly but all the Laravel routes return 'Not Found' (i.e. not hitting index.php), if I remove the rewrite rule everything works.

The .htaccess inside the /public folder is as normal for Laravel:

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

# For all files not found in the file system, reroute the request to the
# "index.php" front controller, keeping the query string intact

<IfModule mod_rewrite.c>
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

2条回答
再贱就再见
2楼-- · 2019-06-03 03:21

This .htaccess is working for me:

<IfModule mod_rewrite.c>
    #Options -MultiViews
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{SERVER_PORT} 80
    RewriteRule ^(.*)$ https://mysite.com/$1 [R,L]
</IfModule>
查看更多
Summer. ? 凉城
3楼-- · 2019-06-03 03:23

After some hours debugging it seems simple now: my default-ssl config did not have the line

AllowOverride All

To enable the htaccess to be read

查看更多
登录 后发表回答