从重定向的URL与htaccess的删除查询字符串 [英] Remove query string from redirected URL with htaccess

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

问题描述

我用下面的code将流量重定向到一个spesific页(此流量通过谷歌从以前用我的服务器IP的旧址未来)

 重写规则^ viewtopic.php?/?$ http://www.myurl.org.uk/ [L,R = 301]
 

据我所知,这个 ^ viewtopic.php?/?$ 应剥去查询字符串,但它不能正常工作。任何帮助AP preciated。

为例网址

  http://www.myurl.org.uk/viewtopic.php?f=3&t=44207&start=2265
 

重定向输出时

  http://www.myurl.org.uk/?f=3&t=44207&start=2265
 

解决方案

您已经接近答案... ...你有在错误的一边。把它放在重定向边去掉查询字符串:

 重写规则^ viewtopic.php http://www.myurl.org.uk/? [L,R = 301]
 

在301重定向,mod_rewrite的,通常会添加完整的查询字符串。但是,将一个在你重写URL的末尾却没有相应的 [QSA] (查询字符串附加)标志将指示它,而不是使用你提供的空白查询字符串。

I'm using the following code to redirect traffic to a spesific page (this traffic is coming via google from an old site which used to use my servers ip)

RewriteRule ^viewtopic.php?/?$ http://www.myurl.org.uk/ [L,R=301]

As I understand it this ^viewtopic.php?/?$ should strip away the query string but it isn't working. Any help appreciated.

Example URL

http://www.myurl.org.uk/viewtopic.php?f=3&t=44207&start=2265

Output when redirected

http://www.myurl.org.uk/?f=3&t=44207&start=2265

解决方案

You were close to the answer... You have the ? on the wrong side. Put it on the redirect side to strip off the query string:

RewriteRule ^viewtopic.php http://www.myurl.org.uk/? [L,R=301]

In a 301 redirect, mod_rewrite will normally append the full query string. But placing a ? at the end of your rewritten URL without a corresponding [QSA] ("querystring append") flag will instruct it instead to use the blank query string you supplied.

这篇关于从重定向的URL与htaccess的删除查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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