【问题标题】:How to 301 redirect domain.com/ to domain.com如何 301 将 domain.com/ 重定向到 domain.com
【发布时间】:2019-01-02 06:24:27
【问题描述】:

如何 301 将 domain.com/ 重定向到 domain.com,所以如果有人打开 domain.com/ 并带有 / 结束,我们需要 301 重定向到 domain.com 而没有 / 结束,这需要影响所有页面:

domain.com/username/ 到 domain.com/username domain.com/tag/lol/ 到 domain.com/tag/lol

【问题讨论】:

    标签: .htaccess redirect http-status-code-301


    【解决方案1】:
    RewriteEngine on
    
    RewriteCond %{REQUEST_FILENAME} !-d
    
    RewriteRule ^(.*)/$ /$1 [L,R=301]
    

    来源: Htaccess: add/remove trailing slash from URL

    【讨论】:

    • 我需要在我的 htaccess 末尾添加你上面写的这两行?
    • 在你的 .htaccess 文件中,在 RewriteEngine On 下面,添加两行
    • 你能在没有<- for test,for prod的情况下编辑这个吗?因为我知道我需要在htaccess中写什么?
    • 现在一切正常!我不知道谁给出了负利率,我也不知道为什么,但这是你的解决方案!
    猜你喜欢
    • 2014-03-18
    • 2023-04-11
    • 2019-10-21
    • 1970-01-01
    • 1970-01-01
    • 2017-01-14
    • 1970-01-01
    • 1970-01-01
    • 2013-02-14
    相关资源
    最近更新 更多