【问题标题】:How to 301 redirect “domain.com/?...” to "domain.com" [duplicate]如何 301 将“domain.com/?...”重定向到“domain.com”[重复]
【发布时间】:2014-03-18 00:09:21
【问题描述】:

当我访问我的“domain.com/?”或“domain.com/?any-other-character-here”它显示我的主页,这会导致 Google 中出现重复的结果。 Web 服务器是 Apache。

我的代码是

ErrorDocument 404 domain.com/error404.html

RewriteEngine On

RewriteCond %{HTTP_HOST} ^domain.com

RewriteRule (.*) domain.com/$1 [R=301,L]

RewriteCond %{THE_REQUEST} \s/+\?\s

RewriteRule ^ /? [R=301,L]

它将非 www 重定向到 www,我在其中添加了您的代码。但仍然看到 domain.com/?any-random-text 不会重定向到 404

【问题讨论】:

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


    【解决方案1】:

    要修复 404 和 domain.com/? 的问题,您可以使用以下代码重写:

    ErrorDocument 404 http://domain.com/error404.html
    
    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} \s/+\?
    RewriteRule ^ /? [R=301,L]
    

    【讨论】:

    • 谢谢,但请更新您对我编辑的问题的回答。这个问题更清楚我需要什么。
    • 这就是你去掉接受标记的原因吗?在任何情况下,我的答案仍然符合重复删除要求,因为我使用 301 将修复 dup 结果。
    • 您的代码仅重定向 domain.com/?但不是 domain.com/?...
    • 我不知道你为什么免费这样做,但我只能说谢谢,太棒了!
    • 这看起来很完美。再次感谢
    猜你喜欢
    • 2019-01-02
    • 2023-04-11
    • 2019-10-21
    • 1970-01-01
    • 1970-01-01
    • 2017-01-14
    • 1970-01-01
    • 1970-01-01
    • 2013-02-14
    相关资源
    最近更新 更多