简体   繁体   中英

.htaccess redirect from index.php not working

I did my best to search in stack overflow questions and answers and even when I tried to apply a solution, it is not working.

I need to redirect all adresses, that begin with

http://www.example.com/index.php?lang=XX

to

http://www.example.com/XX

This is what I try:

RewriteCond %{HTTP_HOST} ^www.example\.com [NC]
RewriteRule ^(index\.php\?lang\=)$ http://www.example.com/$1 [L,R=302]

The location /index.php?lang=en is not redirecting /en (anywhere). It is at the same URL.

You can't match a query_string in a rewriterule. You need a specific RewriteCond for it. It should be more or less like this:

RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteCond %{QUERY_STRING} ^lang=(.*)
RewriteRule ^ http://www.example.com/%1 [R=302,L,QSD]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM