.htaccess - 使用 .htaccess 在两个页面上强制使用 http

标签 .htaccess http ssl https

我想使用 .htaccess 文件将页面从 HTTPS 重定向到 HTTP。

我已经为一个页面添加了代码,但是当我为第 2 页添加代码时,它给网站带来了重定向错误。

这是我的代码,适用于在 .htaccess 中从 HTTPS 到 HTTP 的一页,我还确保 .htaccess 与我想要重定向的文件位于该目录中。

RewriteCond %{SERVER_PORT} 80

RewriteCond %{REQUEST_URI} !^/page1.php$ [NC]

RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L]


RewriteCond %{SERVER_PORT} !80

RewriteCond %{REQUEST_URI} ^/page1.php$ [NC]

RewriteRule ^(.*)$ http://mywebsite.com/$1 [R,L]

但是当我像下面这样添加它时它不起作用并且我收到重定向错误。

RewriteCond %{SERVER_PORT} 80

RewriteCond %{REQUEST_URI} !^/page1.php$ [NC]

RewriteCond %{REQUEST_URI} !^/page2.php$ [NC]

RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L]


RewriteCond %{SERVER_PORT} !80

RewriteCond %{REQUEST_URI} ^/page1.php$ [NC]

RewriteCond %{REQUEST_URI} ^/page2.php$ [NC]

RewriteRule ^(.*)$ http://mywebsite.com/$1 [R,L]

我希望页面仅使用 .htaccess 文件无错误地转到 HTTP:

http://mywebsite.com/page1.php http://mywebsite.com/page2.php

最佳答案

我想通了。我需要的正确代码如下:

重写条件 %{SERVER_PORT} 80

RewriteCond %{REQUEST_URI} !^/(page2.php$|page1.php$) [NC]

重写规则 ^(.*)$ https://www.mywebsite.com/ $1 [R,L]

重写条件 %{SERVER_PORT} !80

RewriteCond %{REQUEST_URI} ^/(page2.php$|page1.php$) [NC]

重写规则 ^(.*)$ http://mywebsite.com/ $1 [R,L]

关于.htaccess - 使用 .htaccess 在两个页面上强制使用 http,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56134387/

相关文章:

php - 获取301重定向的使用统计

wordpress - 将 URL 重写规则添加到 Wordpress

c# - 递归 HTTP 调用在 IDE 中表现出不同的行为与已部署的可执行文件

http - Curl 说它无法解析主机,但可以解析主机

azure - 将应用服务证书与 Azure 应用程序网关结合使用

php - 在特殊的 Query_string 上重定向 .htaccess

apache - .htaccess 文件会被黑客攻击吗?

http - 如何使用 Rebol 3 将 URL 传递给 cookie 并获取响应 cookie?

macos - SSL 握手时出现 OS X Keychain 访问提示

ssl - 为 Jetty 配置 SSL 密码套件