【问题标题】:redirect a page to root using htaccess使用 htaccess 将页面重定向到 root
【发布时间】:2015-08-10 20:29:26
【问题描述】:


这是关于使用以下永久链接的 WP 网站:
http://example.com/article/%postname%/
和“类别”的类别基础。

网站有许多带有固定链接的文章,例如:
http://example.com/article/
http://example.com/article/first-article
http://example.com/article/second-article
http://example.com/article/third-article
等等

他们工作正常,但我想重定向
http://example.com/article

http://example.com/

所以我编辑 htaccess 并插入以下指令:
重定向301/文章http://example.com

虽然此重定向有效,但它实际上破坏了 WP 永久链接,因为永久链接为
http://example.com/article/third-article
的文章 正在被重定向到
http://example.com/third-article,这会导致 404

我可以只将 http://example.com/article 重定向到 root 而没有其他子 url 吗?

【问题讨论】:

  • ^article$ 添加 ^ 和 $

标签: php wordpress .htaccess mod-rewrite redirect


【解决方案1】:

是的,通过使用 mod_rewrite 或 RedirectMatch

RedirectMatch:

RedirectMatch ^/article/?$ http://example.com

使用 mod_rewrite:

RewriteRule ^article/?$ / [R,L]

将此规则放在 wordpress 规则之前,并在一切正常后将 [R] 更改为 [R=301],如果您想将其设为永久重定向。

【讨论】:

    猜你喜欢
    • 2020-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多