[英]Apache redirect all to index.php except for existing files and folders
[英]Apache Redirect all to index.php with https
我已经阅读了很多关于这个主题的答案,但没有提到如何结合:
将所有流量重定向到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时系统地返回404的原因是因为...我的域配置文件不完整,我的网站-ssl.conf缺少AllowOverride All指令,这就是为什么它一直正常工作直到我添加了网址重写。 我的非ssl正确设置为url-rewriting所以这就是为什么我花了一点时间才意识到这在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
我希望这会对某人有所帮助。 谢谢您的帮助
只需将https重定向规则保持在其他规则之上:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [NC,L,R]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|public|css|js|robots\.txt)
RewriteRule ^(.*) index.php/params=$1 [L,QSA]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}/index.php
</IfModule>
所以在上面的例子中,如果用户要进入http
链接,两者( re-write
到https
并forward to index.php
)都会发生(我试过并且正在工作)。 但是如果用户直接使用https
,那么你应该在default-ssl
对index.php
进行简单的rewriting
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.