我想将所有请求重定向到index.php脚本(不是额外的http请求,只是内部的)。
当请求网址为checkout.html时,应该会重定向到https文件。 所有其他请求应为http。
HTTP到HTTP的工作正常,但HTTP到HTTPS会对index.php发出额外的请求。
以下是我的htaccess文件:
# Redirect http checkout.html to https
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} checkout\.html [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
# Redirect https to http (excluding checkout.html)
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !checkout\.html [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
# all script to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^.*\.html|.php$ /index.php [L]
HTTPS到HTTP(例如_http://.../basket.html):
HTTP到HTTPS(例如_http://.../checkout.html)
出了什么问题?
答案 0 :(得分:1)
以下是解决方案:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} checkout.html [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !checkout.html [NC]
RewriteCond %{REQUEST_URI} !index.php [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
</IfModule>
我需要将以下行添加到“https on”条件:
RewriteCond %{REQUEST_URI} !index.php [NC]