web教程 内容:6

网站301重定不带www跳转带www访问

  • 查看作者
  • 我们大家做网站都会遇到,访问不带www也能访问,访问带www也能访问,对于搜索引擎来说是俩个URL页面呢,这就容易造成权重分散,因此我们要对域名进行301重定向,实现不带www跳转带www访问。

    .htaccess

    RewriteCond %{http_host} ^556z.com [NC]//如果是以根域名访问的
    RewriteRule ^(.*)$ https://www.556z.com/$1 [L,R=301]//重定向到www并请求地址不变

    Web.config

    <rule name="301Redirect" stopProcessing="true">
        <match url="(.*)" />
        <conditions logicalGrouping="MatchAny">
        <add input="{HTTP_HOST}" pattern="^556z\.com$" />
        </conditions>
        <action type="Redirect" url="https://www.556z.com/{R:0}" redirectType="Permanent" />
    </rule>

    Nginx

    server {
        listen       80;
        server_name  umtheme.com;
        return       301 http://www.556z.com$request_uri;
    }

    js跳转

    <script language="javascript">     
    if (document.domain =="umtheme.com")
        this.location = "http://www.556z.com" + this.location.pathname + this.location.search;     
    </script>


    请登录之后再进行评论

    登录
    最新评论
    0U币
    已有849人浏览, 浏览收益0, 礼物收益0, 打赏收益0, 点赞收益0, 广告收益0, 获得总收益0U币
    也可开通会员全场文章免费看
    免费教程