htaccess help: name1/value1/name2/value2 format
I am designing an admin panel, where I want a structure like this:
siteadmin.com/action/edit/开发者_开发问答id/1/
which should return query strings:
action => edit
id=>1
OR
siteadmin.com/action/add/
which shd return:
action =>add
In short, I want something like name1/value1/name2/value2 structure. Here is what I have written:
RewriteRule ^([^/]+)/([^/]+)/ index.php?$1=$2
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/ index.php?$1=$2&$3=$4
But it is taking index_php as well. Any help guys?
Thanks,
The ordering of the RewriteRules is important. Also if they are explicit mappings, you often want the [last]
flag so only one rule matches:
RewriteRule ^from$ to [last]
You should also avoid catch-all patterns, rather define your actions to make it unambigious:
RewriteRule ^(action|noaction|delete|explode)/(\d+)$ index?$1=$2 [L]
Some more tips on serverfault: Everything You Ever Wanted to Know about Mod_Rewrite Rules but Were Afraid to Ask?
Add [L]
at the end of the line of your rewrite rule.
精彩评论