我博客某些链接访问被 301 重定向的奇怪现象 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
请不要在回答技术问题时复制粘贴 AI 生成的内容
brader
V2EX    程序员

我博客某些链接访问被 301 重定向的奇怪现象

  •  1
     
  •   brader 2022-10-19 17:48:55 +08:00 1723 次点击
    这是一个创建于 1091 天前的主题,其中的信息可能已经有所发展或是发生改变。

    博客地址 https://brad.9iqu.cn

    我的博客是使用 hexo 搭建的博客,有些链接会被重定向,不知道这是 hexo 的问题,还是我 nginx 配置的问题。

    比如我博客里面有个页面 a 标签地址是 https://brad.9iqu.cn/tags ,然后它就非要给我 301 重定向到 https://brad.9iqu.cn/tags/ 。反正不带 /后缀的导航标签,基本都被重定向,感觉这样有点影响性能

    下面是我的 nginx 配置

    #重定向到 https 请求 server { listen 80; server_name brad.9iqu.cn; return 301 https://$server_name$request_uri; } #https server { listen 443 ssl http2 ; #SSL 访问端口号为 443 server_name brad.9iqu.cn; ssl_certificate cert/1_brad.9iqu.cn_bundle.crt; #证书文件 ssl_certificate_key cert/2_brad.9iqu.cn.key; #私钥文件 ssl_session_timeout 5m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照这个协议配置 ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;#按照这个套件配置 ssl_prefer_server_ciphers on; #charset koi8-r; #access_log logs/host.access.log main; location / { root /www/hexo-blog/public; index index.html index.htm index.php; } # redirect server error pages to the static page /50x.html error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } # deny access to .htaccess files, if Apache's document root location ~ /\.ht { deny all; } } 
    7 条回复    2022-10-20 18:29:59 +08:00
    proxytoworld
        1
    proxytoworld  
       2022-10-19 18:19:22 +08:00
    有的 cdn 也会这样搞
    brader
        2
    brader  
    OP
       2022-10-19 18:21:27 +08:00
    @proxytoworld 这个我没有上什么 cdn 的,我是在自己服务器自搭的
    Wincer
        3
    Wincer  
       2022-10-19 18:28:56 +08:00
    加几行配置:

    rewrite ^(.+)/+$ $1 permanent;
    rewrite ^(.+)/index.html$ $1 permanent;
    try_files $uri $uri/index.html =404;

    另外,访问被重定向是默认的行为:在访问的 /tags 页面时,网站目录下并没有一个名叫 tags 的文件,而存在一个 tags 的目录,因此给你重定向到了目录下,展示了目录下的 index.html 文件的内容。
    IvanLi127
        4
    IvanLi127  
       2022-10-19 18:31:42 +08:00 via Android
    你的 server 比较严谨,哈哈。他没把 index.html 给你吐出来就不错了
    10935336
        5
    10935336  
       2022-10-19 19:02:17 +08:00
    /tags 代表的是文件
    /tags/ 代表的才是目录
    eason1874
        6
    eason1874  
       2022-10-20 14:48:46 +08:00
    主流 CMS 都这样,会跳转,为了语义统一,区别像 #5 说的那样是文件和目录的区别

    你内页链接统一用带斜杠的就不会有多余跳转了,其他人不小心访问到不带斜杆的就让它自动跳转,没什么负担,对性能影响可以忽略不计
    brader
        7
    brader  
    OP
       2022-10-20 18:29:59 +08:00
    我把顶部导航的路径配置全部换成带 / 后缀的,现在好了
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     965 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 20ms UTC 22:29 PVG 06:29 LAX 15:29 JFK 18:29
    Do have faith in what you're doing.
    ubao snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86