mod rewrite rule for a url with multiple get varia

2019-07-30 15:34发布

问题:

Im new to url rewriting, Im able to build simple rules but unable to build a rule for a url consisting of multiple get variables

My url is: http://www.mywebsite.com/index.php?AKey=fjdsakfd&uid=2&cl=Election&req=Voters

I want a clean url like: http://www.mywebsite.com/voters

Kindly help me in building the correct rewrite rule for the above 'clean url'

回答1:

Put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteRule ^voters/?$ /index.php?AKey=fjdsakfd&uid=2&cl=Election&req=Voters [L,QSA,NC]

EDIT: Based on comments:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?cl=$1&req=$2 [L,QSA]