【发布时间】:2025-11-27 20:20:10
【问题描述】:
我有一个网站需要强制使用 HTTPS,除非特定 URL 以某种模式开头。
问题是我重定向到 index.php 以在我的系统中加载 PHP 控制器。当它重定向到 index.php 时,会再次应用重写规则,但重定向后 %{REQUEST_URI} 变为 index.php,并且可以使用 http 的 URL 被重定向到 https。
有办法解决吗?可能在内部重定向或保持 REQUEST_URI 不变后不再读取规则。
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/ok_with_http
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [QSA,L]
【问题讨论】:
标签: php apache mod-rewrite