从URL内饰查询字符串(S) [英] trim query string(s) from url

查看:128
本文介绍了从URL内饰查询字符串(S)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过我们的脚本生成的某些URL。我需要通过htaccess的修剪所有这些; 我对他们有几百个,因此所有?xxx将必须清洗。

Some urls are generated via our script. I need to trim all these via htaccess; I have a few hundred of them, so all ?xxx have to be cleaned.

例如:

domain.com/page.html?word=gclid=4nwseuoSg 

domain.com/page.html 

或任何开始?,α-并且不需要的其余部分。

or anything starting with ?, the ? and the rest is not needed.

我试过重写规则^ \ $ / [R = 301,L] ,但没有工作?(*):(

I tried RewriteRule ^\?(.*)$ / [R=301,L] but did not work :(

我有什么用,而不是 \?(。*)

推荐答案

不包含查询字符串的路径。使用的RewriteCond匹配任何没有空的查询字符串。

the path doesn't contain the querystring. Use RewriteCond to match any none-empty querystring.

RewriteCond %{QUERY_STRING}  !^$
RewriteRule \.html$ $0 [R=301,L]

我还添加了一个条件,即URL已结束在的.html 以防万一你要添加在未来的一段PHP脚本。

I also added a condition that the url has to end in .html just in case you want to add some php script in the future.

这篇关于从URL内饰查询字符串(S)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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