是否可以重写带有问号的网址?
例如,
http://localhost/mysite/search?tag=mars
变成这样,
index.php?url=search&tag[key_name]=mars
我试过这个,但一点都不好,
RewriteRule ^search?tag=([a-zA-Z0-9\-]+)/?$ index.php?url=search&tag[key_name]=$1&type=tag [L,QSA]
有什么建议么?
编辑:
对于%1
,
RewriteCond %{QUERY_STRING} (?:^|&)tag=([^&]+)
RewriteRule ^search$ index.php?url=search&tag\%5Bkey_name\%5D=%1&type=tag [L]
结果,
print_r($_GET);
Array
(
[url] => search
[tag] => Array
(
[key_name] =>
)
[type] => tag
)
对于%0
,
RewriteCond %{QUERY_STRING} (?:^|&)tag=([^&]+)
RewriteRule ^search$ index.php?url=search&tag\%5Bkey_name\%5D=%0&type=tag [L]
结果,
print_r($_GET);
Array
(
[url] => search
[tag] => Array
(
[key_name] => tag=mars
)
[type] => tag
)