【发布时间】:2014-04-06 14:18:04
【问题描述】:
我想为我的域将非 www 和非 https 的 URL 重定向到 https://www,我实际上有以下 htaccess,可以将非 https 重定向到 https,但仍然允许在没有 www 的情况下访问 domain.com,
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]
我发现我应该使用以下命令来强制 www,但我无法找到最好的位置,谢谢
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteCond %{HTTP_HOST} ^(.+)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
【问题讨论】:
标签: apache .htaccess mod-rewrite redirect apache2