如果URL包含参数,则htaccess重定向到基本URL

问题描述:

我需要将所有包含参数?lang=的网址重定向到我的基本网址.

I need to redirect all url's that contain the parameter ?lang= to my base url.

例如:如果www.example.com/?lang=ru重定向到www.example.com.

For example: If www.example.com/?lang=ru redirect to www.example.com.

我尝试过RedirectMatch,但无法正常工作.

I have tried with RedirectMatch but it's not working.

谢谢!

Redirect*指令不处理查询字符串,因此您需要使用URL重写.

The Redirect* directives do not handle the query string so you need to use URL rewriting instead.

RewriteEngine on

# if the query string contains a parameter called "lang"
RewriteCond %{QUERY_STRING} (?:^|&)lang=
# then redirect (permanently) to /
RewriteRule ^ / [L,R=permanent]