我有一个可以是以下任何一个的网址:
1. example.com/index/var1=word&var2=word&var3=number&var4=number&var5=word&var6=word&page=number
2. example.com/index/var1=word&var2=word&var3=number&var4=number&var5=word&var6=word
3. example.com/index/var1=word&var3=number&var4=number&var5=word&var6=word&page=number
4. example.com/index/var1=word&var3=number&var4=number&var5=word&var6=word
这是我目前的htaccess:
RewriteCond %{THE_REQUEST} /index\?var1=([^&\s]+)&var2=([^&\s]+)&var3=([^&\s]+)&var4=([^&\s]+)&var5=([^&\s]+)&var6=([^&\s]+) [NC]
RewriteRule ^ index/%1/%2/%3/%4/%5/%6? [L,R=302,NE]
RewriteRule ^index/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ index.php?var1=$1&var2=$2&var3=$3&var4=$4&var5=$5&var6=$6&page=$7 [L,QSA]
RewriteRule ^index/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ index.php?var1=$1&var2=$2&var3=$3&var4=$4&var5=$5&var6=$6 [L,QSA]
RewriteRule ^index/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ index.php?var1=$1&var3=$2&var4=$3&var5=$4&var6=$5 [L,QSA]
网址1,2和4正在运行,但网址3正在读取为:
3. RewriteRule ^index/([^/]+)/([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ index.php?var2=$1&var3=$2&var4=$3&var5=$4&var6=$5 [L,QSA]
需要改变什么?
答案 0 :(得分:0)
您可以在条件和规则模式中选择匹配第二个参数:
RewriteCond %{THE_REQUEST} /index\?var1=([^&\s]+)(?:&var2=([^&\s]*/?))?&var3=([^&\s]+)&var4=([^&\s]+)&var5=([^&\s]+)&var6=([^&\s]+) [NC]
RewriteRule ^ index/%1/%2%3/%4/%5/%6? [L,R=302,NE]
RewriteRule ^index/([^/]+)/([^/]*/)?([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ index.php?var1=$1&var2=$2&var3=$3&var4=$4&var5=$5&var6=$6&page=$7 [L,QSA]