Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.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
Mod rewrite regex没有特定的url序列_Regex_.htaccess_Mod Rewrite - Fatal编程技术网

Mod rewrite regex没有特定的url序列

Mod rewrite regex没有特定的url序列,regex,.htaccess,mod-rewrite,Regex,.htaccess,Mod Rewrite,我有一个这样的URL结构 mydomain.com/category/--_brand/---color.html 因此,品牌总是以--开头,颜色总是以--开头。但是,URL部分的顺序和数量可能会发生变化,例如: mydomain.com/category/---color.html or mydomain.com/category/---color/--_brand.html 重写规则的结果应该是这样的: index.php?category=$1&color=$2&

我有一个这样的URL结构

mydomain.com/category/--_brand/---color.html
因此,品牌总是以
--
开头,颜色总是以
--
开头。但是,URL部分的顺序和数量可能会发生变化,例如:

mydomain.com/category/---color.html    or
mydomain.com/category/---color/--_brand.html
重写规则的结果应该是这样的:

index.php?category=$1&color=$2&brand=$3
目前,我只有.htaccess中的以下内容:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/?(.*)\.html$ index.php?category=$1&color=$2 [L,QSA]
因此,它只针对类别和颜色,不检查颜色是否以“---”开头,如果URL部分的顺序发生变化,这将是一个问题。
提前感谢您的帮助

以下规则将处理
/category/--u brand/--color.html
/category/--color.html
URL,即当品牌可选出现时

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/(?:--_([^/]+)/)?---(.*)\.html$ index.php?category=$1&brand=$2&color=$3 [L,QSA]
对于
/category/--color/--u brand.html
,您需要另一条规则,即当颜色和品牌的显示顺序发生变化时

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/---([^/]+)/--_(.*)\.html$ index.php?category=$1&color=$2&brand=$3 [L,QSA]

很好的回答+1,它应该可以工作,但我必须说非常奇怪的要求。