.htaccess RewiteCond (QUERY_STRING) with 2 variabl

2019-06-07 05:49发布

问题:

I need to rewrite my url from:

http://***.com/index.php?cat=VAR&page=1

to:

http://***.com/VAR/1

With 301 redirection.

I got this so far:

RewriteCond %{THE_REQUEST} ^(GET|POST)\ /index.php\?
RewriteCond %{QUERY_STRING} ^cat=(.*)\&page=(.*)
RewriteRule . /%1/%2 [R=301]

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/(files|admin)/
RewriteRule ^(.*)/(.*)$ /index.php?cat=$1&page=$2 [L]

But the first 3 rules doesn't seems to work at all. (I'm a beginner in htaccess)

How can i fix this problem? Thanks!

EDIT : Thanks to Jassie, the solution:

RewriteCond %{THE_REQUEST} ^(GET|POST)\ /index.php\?
RewriteCond %{QUERY_STRING} ^cat=(.*)\&page=(.*)
RewriteRule ^(.*)/(.*)$ /index.php?cat=$1&page=$2 [L,QSA]

RewriteEngine On

RewriteCond %{REQUEST_URI} !^/(files|admin)/
RewriteRule ^(.*)/(.*)$ /index.php?cat=$1&page=$2 [L]

回答1:

change it to RewriteRule ^(.)/(.)$ /index.php?cat=$1&page=$2 [L,QSA] and try