【问题标题】:How to merge 2 rewrite rule using Apache mod_rewrite module in php如何在 php 中使用 Apache mod_rewrite 模块合并 2 个重写规则
【发布时间】:2017-09-05 23:14:57
【问题描述】:

我想知道是否可以合并 2 条重写规则。我正在使用 Apache mod_rewrite 模块。

规则 #1

RewriteRule ^albums/singles/?$ discography/discography.php?primarytype=2 [L,QSA]

规则 #2

RewriteRule ^albums/ep/?$ discography/discography.php?primarytype=3 [L,QSA]

我可以合并这两条规则吗?

【问题讨论】:

    标签: php mod-rewrite


    【解决方案1】:
    RewriteRule ^albums/(singles|ep)/?$ discography/discography.php?primarytype=2 [L,QSA]
    

    看看这对你有用吗?我暂时没有测试过。

    第一部分是正则表达式,第二部分是要重写的 url。所以在第二个网址中,我认为这 (2|3) 可能不起作用。

    实际上,您可以在 RewriteCond 中捕获 url 的动态部分,然后将其用作 primarytype=$1

    也就是说,您的结果 url 可以变为 primarytype=ep 或 primarytype=singles,但它们似乎不能动态变为 2 或 3。

    RewriteRule ^albums/(singles|ep)/?$ discography/discography.php?primarytype=$1 [L,QSA]
    

    上面可能是您使用primarytype=ep 或primarytype=singles 生成网址的一个选项,但似乎不能像您在问题中提到的那样动态选择2 或3。

    【讨论】:

    • 好的,让我检查一下
    猜你喜欢
    • 2013-09-08
    • 1970-01-01
    • 2023-03-18
    • 2011-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多