2017-09-05 32 views
1

我想知道是否可以合并2个重写规则。我正在使用Apache mod_rewrite模块。如何在php中使用Apache mod_rewrite模块来合并2重写规则

规则#1

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

规则#2

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

我可以合并那些2个规则?

回答

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

看看这是否适合您?我现在还没有测试过。

第一部分是正则表达式第二部分是要重写的url。所以在第二个网址我认为这(2 | 3)可能无法正常工作。

其实你可以捕捉的RewriteCond URL的动态部分,然后使用它作为primarytype = $ 1

那是你的结果网址可以成为primarytype = EP或primarytype =单打,但它似乎像他们可以不动态地做2或3。

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

以上可能会为你生成具有primarytype = EP或primarytype =单打的网址,但它似乎并不像2或3,可以动态地选择像你在问题中所提到的选项。

+0

不幸的是,它不起作用 – Marco

+0

好吧,让我检查 – muasif80