我可以一次性将非www和/或非https重定向到https:// www吗?

时间:2014-12-04 06:52:24

标签: apache .htaccess mod-rewrite redirect apache2

我想重定向:

http://www -> httpS://www
http://    -> httpS://WWW
https://   -> https://WWW

在一次重定向移动301中,像谷歌一样!

你能帮我做一下吗?

按照.htaccess制作重定向循环

RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.mydomain.com%{REQUEST_URI} [R=301,L,NE]

# Remove Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} \s(.+?)/+[?\s]
RewriteRule ^(.+?)/$ /$1 [R=301,L,NE]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

更新1

通过关注htaccess,我收到302 https://www

找不到
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI}$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}$1

我有两个cname记录,一次是www.mydomain.com,另一次是mydomain.com

0 个答案:

没有答案