我想使用 .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/