简体   繁体   中英

RegEx htaccess remove variable

Sorry, but I couldn't find any help for my problem. Hoping you guys can help.

I have the url: http://example.com/many-pages ?lang=xx

I would like to turn that into just: http://example.com/many-pages

Stripping away the " ?lang=xx " where " xx " is the language code. Also make it a 301 redirect.

Put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+([^?]*)\?lang=[^\s&]+ [NC]
RewriteRule ^ /%1? [R=301,NE,L]

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