.htaccess从http://www.domain/重定向到https://domain.com

时间:2014-03-12 16:17:08

标签: apache .htaccess

我如何(使用htaccess文件)重定向看起来像这样的页面:

http://www.domain/page/?var=test&var2=test2

看起来像这样:

 https://domain/page/?var=test&var2=test2

但这样做只会影响这个页面而不会影响其他内容吗?

3 个答案:

答案 0 :(得分:0)

这与this question非常相似。你想要这样的东西:

# Redirect all HTTP traffic to HTTPS, but only if the requested page is /page
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^page/?$
RewriteRule ^(.*)$ https://domain.com/$1 [QSA]

答案 1 :(得分:0)

在两次重写条件之间需要[OR]

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(page(?:/.*)?)$ https://domain.com/$1 [L,R=301,NE]

如果HTTPS关闭,这将重定向到https://domain.com或者如果您的主机名是www.,则会重定向到{{1}}

答案 2 :(得分:0)

试试这个

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]