Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache htaccess仅重定向到一个文件_Apache_.htaccess_Redirect - Fatal编程技术网

Apache htaccess仅重定向到一个文件

Apache htaccess仅重定向到一个文件,apache,.htaccess,redirect,Apache,.htaccess,Redirect,我想将所有请求重定向到index.php脚本(不是额外的http请求,只是内部请求) 当请求url为checkout.html时,应该重定向到https文件。 所有其他请求都应该是http HTTPs到HTTP正常工作,但HTTP到HTTPs会出现对index.php的额外请求 这是我的htaccess文件: # Redirect http checkout.html to https RewriteCond %{HTTPS} off RewriteCond %{REQUEST_URI} che

我想将所有请求重定向到index.php脚本(不是额外的http请求,只是内部请求)

当请求url为checkout.html时,应该重定向到https文件。 所有其他请求都应该是http

HTTPs到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):

  • 301:重定向_https://.../basket.html 到_http://.../basket.html (正确)
  • 200:http响应篮.html
HTTP到HTTPS(例如_http://.../checkout.html)

  • 301:重定向_http://.../checkout.html 到_https://.../checkout.html (正确)
  • 301:重定向_https://.../checkout.html 到_http://.../index.php (不正确)
  • 200:http响应index.php
出了什么问题?

以下是解决方案:

<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}关闭
RewriteCond%{REQUEST_URI}checkout.html[NC]
重写规则^(.*)$https://%{HTTP_HOST}/$1[R=301,L]
在上重写cond%{HTTPS}
重写cond%{REQUEST_URI}!checkout.html[NC]
重写cond%{REQUEST_URI}!index.php[NC]
重写规则^(.*)$http://%{http_HOST}/$1[R=301,L]
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-L
重写规则。*index.php[L]
我需要在“https on”条件中添加以下行:
RewriteCond%{REQUEST\u URI}!index.php[NC]

https://...checkout.html
与第一组或第二组条件都不匹配,因此它会被第三组条件拾取。当您从
http://...checkout.html
对于安全版本,该安全页面请求也会通过所有这些.htaccess条件。我不明白为什么在打开
https://..checkout.html
到index.php(第三个条件)当我打开
http://...basket.html
重定向仅在index.php内部(也是第三个条件),第三个条件不是301重定向。这只是说执行index.php;总是会有对该文件的请求<代码>http://...basket.html既不满足第一组条件,也不满足第二组条件,因此只需由第三组条件处理,即也只需执行index.php,但当请求是
https://...checkout.html
??(示例:)如果我请求,我将获得302重定向。这加上一个301重定向的事实向我表明,真正发生的并不是你问题中.htaccess中的内容。要么是另一个.htaccess文件正在执行重定向,要么是Web服务器上正在进行其他操作。