zblog教程 内容:90

zblog分类url末尾访问不带链接 / 自动加 / 跳转

  • 查看作者
  • zblog正常情况下,用户打开网站文章分类默认是附带斜杠的 “ / ” 所以用户访问没什么问题,但某些第三方聊天平台分享分类链接给朋友,发现平台会自动注释分类末尾反斜杠 “ / ” 导致访问出现404报错。

    举个例子:

    https://www.556z.com/qz

    https://www.556z.com/qz/

    PS:url末尾带斜杠 / 的是指向目录/qz/,不带的是文件/qz,是不同的二个地址。

    跳转方法:

    Apache .htaccess
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^\.]+[^/])$ /$1/ [L,R=301]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    </IfModule>
    IIS6+ISAPI Rewrite 2.X
    [ISAPI_Rewrite]
    RewriteRule /(?!zb_)([^\.]+[^/]) /$1/ [RP,L]
    RewriteRule /default_([0-9]+)\.html /catalog\.asp\?page=$1
    RewriteRule /category/(?!zb_)(.*)_([0-9]+)/ /catalog\.asp\?cate=$1&page=$2
    RewriteRule /category/(?!zb_)(.*)/ /catalog\.asp\?cate=$1
    RewriteRule /author-([0-9]+)_([0-9]+).html /catalog\.asp\?auth=$1&page=$2
    RewriteRule /author-([0-9]+).html /catalog\.asp\?auth=$1
    RewriteRule /tags-([0-9]+)_([0-9]+).html /catalog\.asp\?tags=$1&page=$2
    RewriteRule /tags-([0-9]+).html /catalog\.asp\?tags=$1
    RewriteRule /post/([0-9\-]+)_([0-9]+)/ /catalog\.asp\?date=$1&page=$2
    RewriteRule /post/([0-9\-]+)/ /catalog\.asp\?date=$1
    RewriteRule /post/(?!zb_)(.*)/ /view\.asp\?id=$1
    RewriteRule /(?!zb_)(.*)/ /view\.asp\?id=$1
    IIS6+ISAPI Rewrite 3.X
    #ISAPI Rewrite 3
    RewriteBase /
    RewriteRule ^(?!zb_)([^\.]+[^/])$ /$1/ [NU,R=301]
    RewriteRule ^default_([0-9]+)\.html$ /catalog.asp\?page=$1
    RewriteRule ^category/(?!zb_)(.*)_([0-9]+)/$ /catalog.asp\?cate=$1&page=$2 [NU]
    RewriteRule ^category/(?!zb_)(.*)/$ /catalog.asp\?cate=$1 [NU]
    RewriteRule ^author-([0-9]+)_([0-9]+).html$ /catalog.asp\?auth=$1&page=$2 [NU]
    RewriteRule ^author-([0-9]+).html$ /catalog.asp\?auth=$1 [NU]
    RewriteRule ^tags-([0-9]+)_([0-9]+).html$ /catalog.asp\?tags=$1&page=$2 [NU]
    RewriteRule ^tags-([0-9]+).html$ /catalog.asp\?tags=$1 [NU]
    RewriteRule ^post/([0-9\-]+)_([0-9]+)/$ /catalog.asp\?date=$1&page=$2 [NU]
    RewriteRule ^post/([0-9\-]+)/$ /catalog.asp\?date=$1 [NU]
    RewriteRule ^post/(?!zb_)(.*)/$ /view.asp\?id=$1 [NU]
    RewriteRule ^(?!zb_)(.*)/$ /view.asp\?id=$1 [NU]
    IIS7、7.5、8+Url Rewrite
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
    <system.webServer>
     <rewrite>
      <rules>
        <rule name="//" stopProcessing="true">
         <match url="^(?!zb_)[^\.]+[^/]$"/>
         <action type="Redirect" redirectType="Permanent" url="{R:0}/"/>
        </rule>
        <rule name="Imported Rule Default+Page" stopProcessing="true">
         <match url="^default_([0-9]+)\.html$" ignoreCase="false" />
         <action type="Rewrite" url="catalog.asp?page={R:1}" />
        </rule>
        <rule name="Imported Rule Category+Page" stopProcessing="true">
         <match url="^category-([0-9]+)_([0-9]+).html$" ignoreCase="false" />
         <action type="Rewrite" url="catalog.asp?cate={R:1}&page={R:2}" />
        </rule>
        <rule name="Imported Rule Category" stopProcessing="true">
         <match url="^category-([0-9]+).html$" ignoreCase="false" />
         <action type="Rewrite" url="catalog.asp?cate={R:1}" />
        </rule>
        <rule name="Imported Rule Author+Page" stopProcessing="true">
         <match url="^author-([0-9]+)_([0-9]+).html$" ignoreCase="false" />
         <action type="Rewrite" url="catalog.asp?auth={R:1}&page={R:2}" />
        </rule>
        <rule name="Imported Rule Author" stopProcessing="true">
         <match url="^author-([0-9]+).html$" ignoreCase="false" />
         <action type="Rewrite" url="catalog.asp?auth={R:1}" />
        </rule>
        <rule name="Imported Rule Tags+Page" stopProcessing="true">
         <match url="^tags-([0-9]+)_([0-9]+).html$" ignoreCase="false" />
         <action type="Rewrite" url="catalog.asp?tags={R:1}&page={R:2}" />
        </rule>
        <rule name="Imported Rule Tags" stopProcessing="true">
         <match url="^tags-([0-9]+).html$" ignoreCase="false" />
         <action type="Rewrite" url="catalog.asp?tags={R:1}" />
        </rule>
        <rule name="Imported Rule Date+Page" stopProcessing="true">
         <match url="^date-([0-9\-]+)_([0-9]+).html$" ignoreCase="false" />
         <action type="Rewrite" url="catalog.asp?date={R:1}&page={R:2}" />
        </rule>
        <rule name="Imported Rule Date" stopProcessing="true">
         <match url="^date-([0-9\-]+).html$" ignoreCase="false" />
         <action type="Rewrite" url="catalog.asp?date={R:1}" />
        </rule>
        <rule name="Imported Rule Article" stopProcessing="true">
         <match url="^post/(?!zb_)(.*).html$" ignoreCase="false" />
         <action type="Rewrite" url="view.asp?id={R:1}" />
        </rule>
        <rule name="Imported Rule Page" stopProcessing="true">
         <match url="^(?!zb_)(.*).html$" ignoreCase="false" />
         <action type="Rewrite" url="view.asp?id={R:1}" />
        </rule>
      </rules>
     </rewrite>
    </system.webServer>
    </configuration>
    Nginx
    if (!-f $request_filename){
       rewrite ^/([^\.]+[^/])$ $scheme://$host/$1$2/ permanent;
    }
    if (-f $request_filename/index.html){
       rewrite (.*) $1/index.html break;
    }
    if (-f $request_filename/index.php){
       rewrite (.*) $1/index.php;
    }
    if (!-f $request_filename){
       rewrite (.*) /index.php;
    }

    在网站伪静态规则中加上以上代码,访问不带 / 目录会自动加上  /  访问,防止出现404错误问题。

    请登录之后再进行评论

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