apache-一个重定向规则中的HTTPS和WWW

时间:2018-06-26 13:06:08

标签: apache .htaccess redirect

我需要创建2个条件的重定向:

  • 非WWW到WWW
  • HTTP到HTTPS

例如http://example.com/blog重定向到https://www.example.com/blog,但是只有301个重定向(目前为2) 我尝试过:

RewriteCond %{SERVER_PORT} !=443 [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.example.com/blog/$1 [R=301,L]

但它仍在生成双重重定向。

这是基本的.htaccess:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

该怎么做?

0 个答案:

没有答案