Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.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
.htaccess 使用htaccess将特定页面重定向到https_.htaccess - Fatal编程技术网

.htaccess 使用htaccess将特定页面重定向到https

.htaccess 使用htaccess将特定页面重定向到https,.htaccess,.htaccess,我希望能够将非https请求重定向到https的特定页面。我可以使用从中获得的代码来执行此操作 但是,当用户单击一个不需要https的链接时,我想让他们进入非https页面,而不是https页面。我该怎么做 也就是说,如果他们在page1.php上单击page100.php的链接,它应该转到,而不是像这样: Options +FollowSymlinks RewriteEngine On RewriteBase / #redirect www.mydomain.com to mydomain.

我希望能够将非https请求重定向到https的特定页面。我可以使用从中获得的代码来执行此操作

但是,当用户单击一个不需要https的链接时,我想让他们进入非https页面,而不是https页面。我该怎么做

也就是说,如果他们在page1.php上单击page100.php的链接,它应该转到,而不是像这样:

Options +FollowSymlinks
RewriteEngine On
RewriteBase /

#redirect www.mydomain.com to mydomain.com (or any other subdomain)
RewriteCond %{HTTP_HOST} !^mydomain.com$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [L,R=301]

#force https for certain pages    
RewriteCond %{HTTPS} off
RewriteRule ^(page1|page2|page3|page4)\.php$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]

RewriteCond %{HTTPS} on
RewriteRule !^(page1|page2|page3|page4)\.php$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]

问题是:如何定义哪些页面要重定向,哪些不重定向?您发布的代码正好重定向了特别提到的4个页面。所有其他页面将不会被重定向。至于重定向的4页,它的工作方式,我希望它。我的问题是,从这4个https页面中,点击任何不属于这些页面的页面都应该是非https页面。但现在,它继续使用https。听起来问题不在于你的重写规则。更像是通过https交付的页面内的链接实际上再次指向https页面。可能是因为它们是相对引用,或者是一些提供页面的软件(例如cms)创建了https链接。请注意,当通过http协议从https加载的页面引用到某个页面时,您将在用户端引发警告。另外,由于安全原因,javascript引用之类的东西通常无法工作。所以你要求的是有问题的。是的,链接是相对的,这就是为什么我需要帮助。如果引用是相对的,那么它们指向https服务器。任何重写都无法改变这一点。或者您必须构造http引用(使用生成这些链接的软件或通过更改静态html页面),或者您需要在js级别动态修改目标。您还可以添加进一步的重写规则,再次从https重定向到http,但这听起来很疯狂。问题是:为什么?
Options +FollowSymlinks
RewriteEngine On
RewriteBase /

#redirect www.mydomain.com to mydomain.com (or any other subdomain)
RewriteCond %{HTTP_HOST} !^mydomain.com$ [NC]
RewriteRule ^(.*)$ http://mydomain.com/$1 [L,R=301]

#force https for certain pages    
RewriteCond %{HTTPS} off
RewriteRule ^(page1|page2|page3|page4)\.php$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]

RewriteCond %{HTTPS} on
RewriteRule !^(page1|page2|page3|page4)\.php$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]