使用mod_rewrite,什么RewriteRule(s)会使以下两个示例正常工作?用等号分隔的URL项重写为查询字符串
实施例#1(一个术语):
http://example.net/dir/thanks
-to-
http://example.net/dir/index.php?a=thanks
实施例#2(两个术语):
http://example.net/dir/thanks=stackoverflow
-to-
http://example.net/dir/index.php?a=thanks&b=stackoverflow
注: .htaccess文件位于域根目录的/ dir /之外。
我已经得到接近与此:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)=([^/]*)/?$ index.php?a=$1&b=$2 [L]
然而,与实施例#1尾部的 “=” 是必需的(我想避免)工作。我试过将“=”改为“=?”在正则表达式使其可选,但它然后工作例如#1它失败,例如#2。
谢谢你对我的问题的任何考虑。我是mod_rewrite和正则表达式的新手,真的很难过。
谢谢!你的两个例子在这里也很棒。我真的很感激详细的解决方案;他们帮助我提高了对mod_rewrite的理解。在我的问题投掷飞镖几小时后,我现在看到我要去哪里错了,谢谢你的回答。 – kiteman