Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.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
Regex 相同的重写条件和多个重写规则_Regex_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Regex 相同的重写条件和多个重写规则

Regex 相同的重写条件和多个重写规则,regex,apache,.htaccess,mod-rewrite,Regex,Apache,.htaccess,Mod Rewrite,我的应用程序中有一些审查规则,例如: RewriteCond %{HTTP_HOST} ^(.*)-street\. RewriteRule ^(.*)/(.*)\.html$ index.php?street=%1&$1=$2 [L] RewriteCond %{HTTP_HOST} ^(.*)-street\. RewriteRule ^(.*)$ index.php?street=%1 [L] 如果我键入:example-street.example.com/type/param

我的应用程序中有一些审查规则,例如:

RewriteCond %{HTTP_HOST} ^(.*)-street\.
RewriteRule ^(.*)/(.*)\.html$ index.php?street=%1&$1=$2 [L]
RewriteCond %{HTTP_HOST} ^(.*)-street\.
RewriteRule ^(.*)$ index.php?street=%1 [L]
如果我键入:example-street.example.com/type/param.html,我希望它使用以下规则:

RewriteRule ^(.*)/(.*)\.html$ index.php?street=%1&$1=$2 [L]
但不幸的是,它使用了较少指定的一个

我应该在代码中添加/更改什么以获得预期结果

编辑 我想达到这个结果:

example-street.example.com/type/param.html->index.php?street=example&type=param

example-street.example.com/whateverelse->index.php?street=example

检查此项,希望它能正常工作


是否要将
example street.example.com/type/param.html
重定向到
index.php
@SahilGulati example-street.example.com/type/param.html->index.php?street=example&type=param@SahilGulatiexample-street.example.com/whateverelse->index.php?street=example提供您得到的不需要的输出。另外,我怀疑你的两个俘虏小组比你想象的更贪婪。试着用散文描述一下捕获组应该捕获什么。@J.Marciniak你能检查一下它是否工作正常吗?
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/type/param.html$
RewriteCond %{HTTP_HOST} ([a-z]+)\-([a-z]+)\.example\.com$
RewriteRule ^([a-z]+)\/([a-z]+)\.html$ /index.php?%2=%1&$1=$2    [R=301,L,QSA]

RewriteCond %{REQUEST_URI} ^/[a-z]+$
RewriteCond %{HTTP_HOST} ([a-z]+)\-([a-z]+)\.example\.com$
RewriteRule ^.*$ /index.php?%2=%1    [R=301,L,QSA]