Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php中使用Apache mod_rewrite模块合并2个重写规则_Php_Mod Rewrite - Fatal编程技术网

如何在php中使用Apache mod_rewrite模块合并2个重写规则

如何在php中使用Apache mod_rewrite模块合并2个重写规则,php,mod-rewrite,Php,Mod Rewrite,我想知道是否可以合并两条重写规则。我正在使用Apache mod_重写模块 规则#1 规则2 我可以合并这两条规则吗 RewriteRule ^albums/(singles|ep)/?$ discography/discography.php?primarytype=2 [L,QSA] 看看这对你有用吗?我现在还没有测试过 第一部分是正则表达式,第二部分是要重写的url。所以在第二个url中,我认为这(2 | 3)可能不起作用 实际上,您可以在RewriteCond中捕获url的动态部分,然

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

规则#1

规则2

我可以合并这两条规则吗

RewriteRule ^albums/(singles|ep)/?$ discography/discography.php?primarytype=2 [L,QSA]
看看这对你有用吗?我现在还没有测试过

第一部分是正则表达式,第二部分是要重写的url。所以在第二个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的URL的一个选项,但似乎不能像您在问题中提到的那样动态选择2或3。

好,让我检查一下
RewriteRule ^albums/(singles|ep)/?$ discography/discography.php?primarytype=2 [L,QSA]
RewriteRule ^albums/(singles|ep)/?$ discography/discography.php?primarytype=$1 [L,QSA]