【问题标题】:redirect 404 urls with query handling使用查询处理重定向 404 url
【发布时间】:2012-06-17 21:59:02
【问题描述】:

处理所有带有site.com/p/QUERY 的查询,但有些用户错误地使用site.com/QUERY 进行请求,他们看到404 错误页面。

如何将site.com/QUERY 重定向到site.com/p/QUERY 并通过.htaccess 避免404 错误?

在 htaccess 教程和问题中没有找到任何解决方案。

【问题讨论】:

    标签: .htaccess http-status-code-404


    【解决方案1】:

    使用这个

    <Files index.php>
    order allow,deny
    deny from all
    </Files>
    # Turn on URL rewriting
    RewriteEngine On
    Options +FollowSymLinks
    # Installation directory
    RewriteBase /
    # Allow these directories and files to be displayed directly:
    RewriteCond $1 !^(index\.php|robots\.txt|favicon\.ico|img|js|css|media)
    # Rewrite all other URLs to /p/URL
    RewriteRule ^([^/]+)$ /p/$1  [PT,L]
    # Rewrite all other URLs to /p/URL or /p/some.html?var=1&var2=2
    RewriteRule ^(.*)$ /p/$1  [PT,L]
    

    【讨论】:

    • index.php、login.php 等需要一些例外。只需要重定向的查询。
    • 只有 GET 查询,你的意思是?喜欢 site.com/p/?a=bnot site.com/p/a/b ?
    • 通过数据库中存在的部分检查收到的 url
    • @h2ooooooo 查询有时直接通过 url 插入。像这样:site.com/q/TYPED-IN-HERE - @luther: 去测试它.. 谢谢。
    猜你喜欢
    • 2020-11-09
    • 1970-01-01
    • 2011-12-08
    • 2016-09-20
    • 1970-01-01
    • 2019-12-19
    • 2014-08-24
    • 2014-11-03
    相关资源
    最近更新 更多