【发布时间】:2016-05-10 03:47:46
【问题描述】:
我已经阅读了很多关于这个主题的答案,但没有一个提到如何结合:
将所有流量重定向到 index.php + 将所有 http 重定向到 httpS
以下内容非常适合将所有重定向到 index.php :
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|public|css|js|robots\.txt)
RewriteRule ^(.*) index.php/params=$1 [L,QSA]
在我这样做之前,我可以使用这个来强制 http 到 https:
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
我只是找不到一种方法来混合两者,所以它会使用相同的条件将所有流量重定向到 index.php 并强制 https。
* 编辑 *
以防其他人像我一样感到困惑。
当我调用重写的 url 时,https 系统地返回 404 的原因是……我的域配置文件不完整,我的 website-ssl.conf 缺少 AllowOverride All 指令,这就是为什么在我添加 url 重写之前一切正常。我的非 SSL 正确设置为 url 重写,所以这就是为什么我花了一点时间才意识到这在 https 时不起作用。
然后我在 /etc/apache2website-ssl.conf 中添加了必要的内容
<Directory /var/www/vhosts/exemple.com>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
</Directory>
这在我的 .htaccess 中
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://exemple.com/$1 [R,L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|public|css|js|robots\.txt)
RewriteRule ^(.*) index.php/params=$1 [L,QSA]
ErrorDocument 404 /index.php
我希望这会对某人有所帮助。 谢谢你的帮助
【问题讨论】:
-
甚至没有查看您的代码,您是否真的尝试将所有代码放在同一个文件中? (保存重复的
RewriteEngine和RewriteBase指令。) -
这都在同一个.htaccess 是的,当我尝试两者时我没有重复RewriteEngine
标签: php apache .htaccess https bootstrapping