首页 > 解决方案 > 如何在 htaccess 中仅删除一个 .php 文件的 https 重定向

问题描述

我只想为一个 .php 文件删除我的网页的 https 重定向。我找到了这个,但我不知道如何设置我的 .php 方向。提前致谢

.php 文件 = www.myhost.com/myphp.php

# force http:// for selected URLs
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} /commerce_paypal/ [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

标签: apache.htaccessmod-rewrite

解决方案


你的情况发生了逆转。你需要使用这个:

# force https:// to all but selected URLs
RewriteCond %{HTTPS} !on
RewriteCond %{THE_REQUEST} !\s/+myfile\.php [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# force http:// to selected URLs
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} \s/+myfile\.php [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

推荐阅读