将非www和非https重定向到https:// www

时间:2014-04-06 14:18:05

标签: apache .htaccess mod-rewrite redirect apache2

我想将非www和非https网址重定向到我的域https://www,我实际上有以下htaccess,可以将非https重定向到https,但仍允许访问{{1}没有www,

domain.com

我发现我应该使用以下内容强制使用www,但我无法获得最佳位置,谢谢

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI}%{QUERY_STRING} [L,R]

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]

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

1 个答案:

答案 0 :(得分:1)

您可以使用:

RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.domain.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]