http, www网站定向到https, non-www网站

今天把小站的http://mspace.tech, https://www.mspace.top, https://wwww.mspace.tech访问都重定向到了https://mspace.tech上,具体方法是在网站根目录的.htaccess文件中加入以下代码: [code]<IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ https://%1/$1 [R=301,L] RewriteCond %{HTTPS} !on RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] </IfModule>[/code] 同理,如果我们想要将网站的其它三种形式的网址访问重定向到https://www.mspace.top,.htaccess文件中可以这样写: [code]<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{HTTPS} off [OR] RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC] RewriteRule ^ https://www.%1%{REQUEST_URI} [L,NE,R=301] </IfModule>[/code]
← 返回博客列表

评论 (0)

暂无评论,快来发表第一条评论吧!