【问题标题】:Rewrite rule multiple folders重写规则多个文件夹
【发布时间】:2019-12-12 11:45:42
【问题描述】:

我不知道如何为 .htaccess 重写规则 如果有可能的话。 我做错了什么,因为这例如不起作用。

重写引擎开启 RewriteRule (.*)information/(.*)$information.php?slug=$1 [L] RewriteRule (.*)informatie/search/(.*)$ informatie-search.php?slug=$1 [L]

使用 website.com/information/content 时调用第一个重写规则(我在该页面上查询 /content 之后的内容,例如 website.com/information/content/locations)

使用 website.com/information/search 时调用第二个重写规则(我在该页面上查询 /search 之后的内容,例如 website.com/information/search/books)

【问题讨论】:

  • 这里没有实际的、可辨别的问题。您向我们展示的代码到底有什么问题?请阅读How to Ask,然后相应地编辑您的问题。
  • 第二条规则中的informatie 是错字吗?你说 URL 实际上是/information/search。 (在这种情况下,您当然必须颠倒两条规则的顺序,否则第一个将捕获/information/search。)

标签: .htaccess url mod-rewrite url-rewriting


【解决方案1】:

我修改了规则,请检查:

<IfModule mod_rewrite.c>
    RewriteEngine on

    # /information/any to /information.php?slug=any
    RewriteRule ^information\/(.*)$ /information.php?slug=$1 [L]

    # /informatie/search/any to /informatie-search.php?slug=any
    RewriteRule ^informatie\/search\/(.*)$ /informatie-search.php?slug=$1 [L]

</IfModule>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-16
    • 2012-11-22
    • 2012-11-20
    • 1970-01-01
    相关资源
    最近更新 更多