[英]Redirect all non-www to www for both http and https with .htaccess
[英]Redirect non-www to www for both http and https
我希望获得以下 2 个页面来重定向 www. 各自主机的版本;
http://website.co.uk > redirect to > http://www.website.co.uk
和
https://website.co.uk > redirect to > https://www.website.co.uk
我需要让 HTTP 和 HTTPs 为各自的 URL 工作。
您可以使用此单一规则在http
和https
添加www
:
# for Apache 2.4+ use this rule
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ %{REQUEST_SCHEME}://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
如果您使用的是较旧的 Apache 版本,请使用以下规则:
# for Apache 2.2
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
您是否尝试使用 RewriteEngine 规则? 以下应该可以解决问题(将其应用于 vhost 80 和 443):
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.website.co.uk$1 [R=301,L]
#for 80 port: RewriteRule ^(.*)$ http://www.website.co.uk$1 [R=301,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.