我正在使用以下 .htaccess 文件将某些页面重定向到 https://
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (sale|success|cancel)
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !(static|sale|success|cancel)
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301]
RewriteCond $1 !^(index\.php|resources|robots\.txt|static)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
这是可行的,除了当您转到重写为 https://
的页面时,它还会在 URL 中插入 index.php
。一切正常,但我希望不要插入 index.php
。有任何想法吗?
谢谢。
最佳答案
您的前 2 条规则中缺少 L
标志。
您可以使用此代码:
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (sale|success|cancel) [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !(static|sale|success|cancel) [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond $1 !^(index\.php|resources|robots\.txt|static) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
关于.htaccess - 用于 SSL 插入 index.php 的 Codeigniter .htaccess 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19563685/