Lost305
Lost305

Reputation: 175

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.

Upvotes: 2

Views: 28

Answers (1)

anubhava
anubhava

Reputation: 785481

Put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

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

Upvotes: 2

Related Questions