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

时间:2014-05-04 12:02:43

标签: .htaccess

我希望能够将非https请求重定向到特定页面到https。我可以使用从htaccess redirect 4 specific pages to https

获得的代码来完成此操作
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} !=on
RewriteRule ^(page1\.php|page2\.php|page3\.php|page4\.php)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]

但是当用户点击不是需要https的链接时,我想将它们带到非https页面而不是https页面。我怎么能这样做?

如果他们点击page1.php上的page100.php的链接,它应该转到http://domain.com/page100.php而不是https://domain.com/page100.php

1 个答案:

答案 0 :(得分:0)

有这样的话:

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]
相关问题