如果URL包含参数,则htaccess重定向到基本URL [英] htaccess redirect to base URL if URL contains parameter

查看:97
本文介绍了如果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]

这篇关于如果URL包含参数,则htaccess重定向到基本URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆