伪静态规则可以做301重定向,不同的环境下,写的代码不一样。现在比较常见的三种环境是:nginx、apache、iis。这三种情况下,代码是不同的。
一、nginx的规则实例如下
rewrite ^/$ https://www.weijingtai.org/about/contact.html permanent;
以上是单条的跳转规则。以下是所有的http跳转到https的
if ($server_port !~ 443){
rewrite ^/.*$ https://$host$request_uri permanent;
}
如果是需要某一个域名的跳转,是这样做的:
server {
listen 80;
server name www.weijingtai.org;
rewrite ^/(.*)$ https://www.weijingtai.org/$1 permanent;
}
二、apache的301跳转规则实例如下:
RewriteRule ^(.*)$ https://www.weijingtai.org/$1 [R=301,L]如果是http跳转到https,则这样写:
RewriteEngine on
RewriteBase /
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
上边的代码,就是所有http跳转到https的。判断他不是443端口,就跳转到https的网址上。这个代码是适合apache服务器上的。
三、IIS上web.config的跳转规则实例如下:
<rule name="301Redirect" stopProcessing="true">
<match url="(.*)" />
<conditions logicalGrouping="MatchAny">
<add input="{HTTP_HOST}" pattern="^390seo.com$" />
</conditions>
<action type="Redirect" url="http://www.390seo.com/{R:0}" redirectType="Permanent" />
</rule>
如果是http全部跳转到http,则是这样的代码:
<rule name="HTTP2HTTPS" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
<add input="{HTTPS_HOST}" pattern="^(localhost)" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" />
</rule>
还没有人来评论,快来抢个沙发吧!