301跳转https和www

Fork Me On Github
zodream 其他技术 2020年05月

强制使用https访问

Apache 做法

修改网站根目录下的 .htaccess 文件

   
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://zodream.cn/$1 [R,L]
123

nginx 做法

     
server {
    listen       80;
    server_name  zodream.cn;
    return 301 https://$server_name$request_uri;
}
12345

iis 做法

修改网站根目录下的 web.config 文件

xml
                
<?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>
12345678910111213141516

无www 跳转带www

Apache 做法

修改网站根目录下的 .htaccess 文件

   
RewriteEngine on
RewriteCond %{HTTP_HOST} ^zodream.cn [NC]
RewriteRule ^(.*)$ http://www.zodream.cn/$1 [L,R=301,NC]
123

nginx 做法

     
server {
    listen       80;
    server_name  zodream.cn;
    return 301 http://www.zodream.cn$request_uri;
}
12345

iis 做法

修改 无www 域名 网站根目录下的 web.config 文件,必须安装 HTTP重定向 功能

xml
      
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <httpRedirect enabled="true" destination="http://www.zodream.cn" httpResponseStatus="Permanent" />
  </system.webServer>
</configuration>
123456

www 跳转无www

Apache 做法

修改网站根目录下的 .htaccess 文件

   
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.zodream.cn [NC]
RewriteRule ^(.*)$ http://zodream.cn/$1 [L,R=301,NC]
123

nginx 做法

     
server {
    listen       80;
    server_name  www.zodream.cn;
    return 301 http://zodream.cn$request_uri;
}
12345

iis 做法

修改 带www 域名 网站根目录下的 web.config 文件,必须安装 HTTP重定向 功能

xml
      
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <httpRedirect enabled="true" destination="http://zodream.cn" httpResponseStatus="Permanent" />
  </system.webServer>
</configuration>
123456

强制其他域名都跳转到一个域名

Apache 做法

修改网站根目录下的 .htaccess 文件

   
RewriteEngine on
RewriteCond %{HTTP_HOST} !^zodream.cn [NC]
RewriteRule ^(.*)$ http://zodream.cn/$1 [L,R=301,NC]
123

nginx 做法

     
server {
    listen       80 default_server;
    server_name  _;
    return 301 http://zodream.cn$request_uri;
}
12345

iis 做法

修改 默认 * 域名 网站根目录下的 web.config 文件,必须安装 HTTP重定向 功能

xml
      
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <httpRedirect enabled="true" destination="http://zodream.cn" httpResponseStatus="Permanent" />
  </system.webServer>
</configuration>
123456
点击查看全文
0 198 0