简体   繁体   English

.htaccess重定向,不带查询参数

[英].htaccess redirect without query parameters

I changed a website and now Google webmaster is loading hundreds of "Not Found" URLs: 我更改了网站,现在Google网站管理员正在加载数百个“未找到” URL:

http://www.domain.com/images/picture.php?idphotos=720,404,,4/1/13,Not found

The picture.php does not exist anymore so I created a .htaccess entry to redirect the root of the site: picture.php不再存在,所以我创建了一个.htaccess条目来重定向网站的根目录:

Redirect 301 /images/picture.php. /

Now the problem is that any query parameters are also sent in the redirect: 现在的问题是所有查询参数也都在重定向中发送:

http://www.domain.com/?idphotos=720

How can I create a redirection which doesn't include the query parameters, eg like this: 如何创建不包含查询参数的重定向,例如:

http://www.domain.com/

Try this (note the trailing ? ): 试试这个(注意尾随的? ):

RewriteCond %{QUERY_STRING} !=""
RewriteRule . http://www.domain.com/?

Alternatively use the QSD flag from Apache 2.4.0 或者使用Apache 2.4.0中的QSD标志

RewriteCond %{QUERY_STRING} !=""    
RewriteRule . http://www.domain.com/ [L,R=301,QSD]

http://httpd.apache.org/docs/current/en/rewrite/flags.html#flag_qsd http://httpd.apache.org/docs/current/en/rewrite/flags.html#flag_qsd

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

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