0

我在 htaccess 重写时遇到了一些问题,我需要将网站的不同部分重定向到 https 而不是 http,例如登录和新闻部分。我不确定如何以正确的方式执行此操作。

所以此刻我有

RewriteRule   ^login/?$  index.php?p=login [R,L]

我想将此重定向到 https,我尝试了以下方法,但它似乎不起作用

RewriteRule ^login/?$ https://%{SERVER_NAME}/index.php?p=login [R,L]

但它似乎不起作用。我错过了什么吗?我已经重写和所有其他设置,因为它们工作。我错过了什么?

无论如何,还有没有让 htaccess 使用 https 设置的不同规则集?

更新:

所以我想要做的是重写http://www.site.tld/login/重写为https://www.site.tld/login/code然后进一步重写为https://www.site.tld/ index.php?p=login。所以用户看到:https://www.site.tld/login/但它实际上是在做https://www.site.tld/index.php?p=login

4

1 回答 1

0
RewriteEngine On
# This will enable the Rewrite capabilities

RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS

RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

具体目录:

RewriteEngine On
# This will enable the Rewrite capabilities

RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS

RewriteRule ^/?secure/(.*) https://%{SERVER_NAME}/secure/$1 [R,L]
# This rule will redirect all users who are using any part of /secure/ to the same location but using HTTPS.
# i.e.  http://www.example.com/secure/ to https://www.example.com/secure/
# This means if you dont want to force HTTPS for all directories you can force it for a specific sub-section of the site.

更多信息:http: //wiki.apache.org/httpd/RewriteHTTPToHTTPS

于 2013-01-19T21:07:03.843 回答