简体   繁体   English

通过htaccess从301重定向中删除查询字符串

[英]Removing query string from 301 redirect via htaccess

I want to redirect URLs like these: 我想重定向如下网址:

http://domain1.com/video.php?id=248
domain1.com/details.php?id=4028

to

http://domain2.com/

But I'm getting the redirects as: 但是我得到的重定向为:

http://domain2.com/?id=248
http://domain2.com/?id=4028

Using the following code in my .htaccess 在我的.htaccess中使用以下代码

RewriteEngine On
RewriteRule .* http://domain2.com/ [R=301,L]

I've experimented with %{QUERY_STRING} but I get no redirect. 我已经尝试过%{QUERY_STRING},但没有重定向。 I don't know what I'm doing. 我不知道我在做什么 Someone please help me! 有人请帮助我!

You need to add a ? 您需要添加一个? to the end of the target to create a new (blank) query string. 到目标的末尾以创建新的(空白)查询字符串。 By default, mod_rewrite will append any existing query string unless one is explicitly created by the rule (in which case a QSA flag is needed to append it): 默认情况下,除非该规则显式创建了mod_rewrite,否则它将附加任何现有查询字符串(在这种情况下,需要QSA标志来附加它):

RewriteEngine On
RewriteRule .* http://domain2.com/? [R=301,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM