你好iam试图在我的htaccess中匹配超过10个变量,但是在第10个变量之后它无法识别并从第一个$ 1开始 - 但我希望" $ 11"不是$ 1
浏览器网址:http://localhost/s/adobe+cs5/58058,18793/111/666/
htaccess重写:
Array ( [search] => adobe cs5 [categories] => Array ( [0] => 58058 [1] => 18793 [2] => ) [pricefrom] => 111 [priceto] => adobe cs51 [email] => adobe cs53 )
RewriteEngine On
RewriteBase /eule2/
RewriteRule ^s/([^/\.]+)/(([0-9]+)(,([0-9]+?))?(,([0-9]+?))?/)(([^/]+)/)?(([^/]+)/)?(([^/]+)/)?((?<email>[^/]+)/)?$
search.php?search=$1&categories[]=$3&categories[]=$5&categories[]=$7&pricefrom=$9&priceto=$11&email=$13 [L]
答案 0 :(得分:1)
你的正则表达式中有很多不必要的可选捕获组。您可以将“可选组”转换为非捕获组,即(?:...)
,以使捕获组的数量少于10个。
您可以使用此规则:
RewriteRule ^s/([^/.]+)/(\d+)(?:,(\d+?))?(?:,(\d+?))?/(?:([^/]+)/)?(?:([^/]+)/)?(?:([^/]+)/)?(?:([^/]+)/)?(?:([^/]+)/)?$ search.php?search=$1&categories[]=$2&categories[]=$3&categories[]=$4&pricefrom=$5&priceto=$6&email=$7 [L,QSA,NC]
这将处理此网址:
http://localhost/s/adobe+cs5/58058,18793/111/666/adobe+cs53/
在GET
中填充这些search.php
参数:
Array
(
[search] => adobe cs5
[categories] => Array
(
[0] => 58058
[1] => 18793
[2] =>
)
[pricefrom] => 111
[priceto] => 666
[email] => adobe cs53
)