.htaccess RewiteCond (QUERY_STRING) with 2 variable and rewrite properly

邮差的信 提交于 2019-12-08 07:45:25

问题


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



来源:https://stackoverflow.com/questions/11099502/htaccess-rewitecond-query-string-with-2-variable-and-rewrite-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!