【问题标题】:Trailing slash mod_rewrite rule for certain subfolders某些子文件夹的尾随斜杠 mod_rewrite 规则
【发布时间】:2017-05-09 18:55:58
【问题描述】:

我正在尝试使尾部斜杠 mod_rewrite 规则仅适用于某些子文件夹。

我有像 //// 这样的文章 URL。例如,文章 URL 可能是 /news/role-playing-games/new-roleplaying-game-released/。有时,无论出于何种原因,人们尝试不带斜杠的 URL 并得到 404。我希望 apache 只在与某些子文件夹匹配的 URL 中添加斜杠。

我试过这条规则,但它不起作用。

RewriteCond %{REQUEST_URI} ^/(news|reviews|tutorials|guides)/(.*)$
RewriteRule ^(.*)$ /$1/ [L,R=301]

谁能告诉我我做错了什么?

提前致谢。

【问题讨论】:

    标签: apache redirect mod-rewrite


    【解决方案1】:

    试试

    RewriteRule ^((news|reviews|tutorials|guides)/[^/]+/[^/]+)$ $1/ [L,R=301]
    

    我假设你提供的 url 结构是唯一的。

    【讨论】:

    猜你喜欢
    • 2011-05-31
    • 1970-01-01
    • 2011-02-20
    • 2010-09-14
    • 2020-05-20
    • 2012-09-25
    • 1970-01-01
    • 2017-12-31
    • 2016-12-17
    相关资源
    最近更新 更多