I have a regular expression for a framework to convert host.com/controller/method
in to host.com/index.php?controller/method
Like this:
RewriteEngine on
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ /index.php/$1 [L]
I now require it to开发者_运维技巧 convert into this,
host.com/controller/method
-> host.com/index.php?controller=$1&method=$2
How would I do a match with a regular expression like so within htaccess?
Something like this?
RewriteRule ^(\w+)/(\w+)$ /index.php?controller=$1&method=$2 [L]
If you just want one path segment instead of just anything, use [^/]
instead of .
:
RewriteCond $1 !=index.php
RewriteRule ^([^/]*)$ /index.php/$1 [L]
And for your second requirement:
RewriteCond $1 !=index.php
RewriteRule ^([^/]*)/([^/]*)$ /index.php?controller=$1&method=$2 [L,QSA]
Here you should also consider to use the quantifier +
(one or more) instead of *
(zero or more).
精彩评论