.htaccess 中的重定向省略参数

Redirect omitting parameters in .htaccess

经过几个小时的努力,我设法生成了一个 htacces 文件,将我所有的旧 URL 重定向到我的新站点(同一域)的 URL。我使用以下规则来管理我的子文件夹重定向(我的新网站只有几页):

RewriteRule ^es/empresa/terminos-y-condiciones.html$ http://domain/terminos-y-condiciones.html [L]
RewriteRule ^es/servicios/registro-de-dominios/.*$ http://domain/dominios.html [R=301,NC,L]
RewriteRule ^es/empresa/.*$ http://domain/nosotros.html [R=301,NC,L]   
RewriteRule ^es/component/.*$ http://domain/contacto.html [R=301,NC,L]
RewriteRule ^es(/.*)?$ / [R=301,NC,L]

问题是,当我尝试访问某些页面时,例如 domain.com/empresa/testimonios-de-clientesc69a.html?lang=es 它会将我重定向到 domain/?lang=es ,那是我的域+".html".

后的参数

所以,我想知道是否有办法消除此参数并仅重定向到 www.domain.com?

提前致谢!

要截断查询字符串,请添加“?”像这样在目标 URL 的末尾签名:

RewriteRule ^es/empresa/.*$ http://domain/nosotros.html? [R=301,NC,L]

在 Apache 2.4 或更高版本上,您可以使用 QSD 标志来丢弃查询字符串 (see documentation):

When the requested URI contains a query string, and the target URI does not, the default behavior of RewriteRule is to copy that query string to the target URI. Using the [QSD] flag causes the query string to be discarded.

所以它看起来像

RewriteRule ^es/empresa/.*$ http://domain/nosotros.html [R=301,NC,L,QSD]