我目前有mod_rewrite和我发现的代码,将所有请求重定向到没有www的同一个URL。
我现在要做的就是配置Apache mod_rewrite来做以下事情,而不会有任何浪费的动作/额外的重定向。
http:// to https://
http://www. to https://我不熟悉它,但在伪代码中,http(s)://(www.)domain.com到https://domain.com仅用于顶层的URL,不包括子域。
发布于 2014-07-06 13:47:51
对于这两个条件,您只需要一条规则:
将以下代码放入DOCUMENT_ROOT/.htaccess文件中:
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://domain.com%{REQUEST_URI} [NE,R=301,L]发布于 2014-07-06 13:48:10
是的,有一种方法可以将这些操作组合到一个规则中:
RewriteCond %{HTTP_HOST} !=example.com [OR]
RewriteCond %{HTTPS} !=on
RewriteRule ^/(.*) https://example.com/$1发布于 2015-07-22 16:13:14
这个对我很有效。我尝试了上面的方法,但它在较旧的浏览器上创建了一个重定向循环。
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]https://stackoverflow.com/questions/24593048
复制相似问题