将非 www 和非 https 重定向到 https://www [英] Redirect non-www and non-https to https://www
本文介绍了将非 www 和非 https 重定向到 https://www的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将非 www 和非 https URL 重定向到我的域的 https://www
,我实际上有以下 htaccess,可以将非 https 重定向到 https,但仍然可以正常工作允许在没有 www 的情况下访问 domain.com
,
I want to redirect non-www and non-https URLs to https://www
for my domain, I actually have the following htaccess, that works ok redirecting non-https to https but still allows to access domain.com
without 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]
我发现我应该使用以下内容来强制使用 www,但我无法将其放置在最佳位置,谢谢
I've found I should use the following to force www, but I can't get where it should be placed for best, thanks
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteCond %{HTTP_HOST} ^(.+)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
推荐答案
您可以使用:
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]
这篇关于将非 www 和非 https 重定向到 https://www的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文