Laravel使用Mod Rewrite强制HTTPS

ben*_*t_w 1 apache mod-rewrite ssl https laravel

我有一个运行Laravel 3的站点需要在apache配置中使用以下重写规则强制https:

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Run Code Online (Sandbox Code Playgroud)

这会正确强制https但是所有Laravel路由都返回'Not Found'(即没有命中index.php),如果我删除重写规则一切正常.

/ public文件夹中的.htaccess对于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>
Run Code Online (Sandbox Code Playgroud)

Ant*_*iro 5

这个.htaccess对我有用:

<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>
Run Code Online (Sandbox Code Playgroud)