强制使用https访问
Apache 做法
修改网站根目录下的 .htaccess
文件
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://zodream.cn/$1 [R,L]
nginx 做法
server {
listen 80;
server_name zodream.cn;
return 301 https://$server_name$request_uri;
}
iis 做法
修改网站根目录下的 web.config
文件
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="HTTP to HTTPS redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
无www 跳转带www
Apache 做法
修改网站根目录下的 .htaccess
文件
RewriteEngine on
RewriteCond %{HTTP_HOST} ^zodream.cn [NC]
RewriteRule ^(.*)$ http://www.zodream.cn/$1 [L,R=301,NC]
nginx 做法
server {
listen 80;
server_name zodream.cn;
return 301 http://www.zodream.cn$request_uri;
}
iis 做法
修改 无www
域名 网站根目录下的 web.config
文件,必须安装 HTTP重定向
功能
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<httpRedirect enabled="true" destination="http://www.zodream.cn" httpResponseStatus="Permanent" />
</system.webServer>
</configuration>
www 跳转无www
Apache 做法
修改网站根目录下的 .htaccess
文件
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.zodream.cn [NC]
RewriteRule ^(.*)$ http://zodream.cn/$1 [L,R=301,NC]
nginx 做法
server {
listen 80;
server_name www.zodream.cn;
return 301 http://zodream.cn$request_uri;
}
iis 做法
修改 带www
域名 网站根目录下的 web.config
文件,必须安装 HTTP重定向
功能
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<httpRedirect enabled="true" destination="http://zodream.cn" httpResponseStatus="Permanent" />
</system.webServer>
</configuration>
强制其他域名都跳转到一个域名
Apache 做法
修改网站根目录下的 .htaccess
文件
RewriteEngine on
RewriteCond %{HTTP_HOST} !^zodream.cn [NC]
RewriteRule ^(.*)$ http://zodream.cn/$1 [L,R=301,NC]
nginx 做法
server {
listen 80 default_server;
server_name _;
return 301 http://zodream.cn$request_uri;
}
iis 做法
修改 默认 *
域名 网站根目录下的 web.config
文件,必须安装 HTTP重定向
功能
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<httpRedirect enabled="true" destination="http://zodream.cn" httpResponseStatus="Permanent" />
</system.webServer>
</configuration>
Reprint please keep the original link: https://zodream.cn/blog/id/134.html