htaccess重定向url,其中包含空格

时间:2012-07-12 01:50:07

标签: .htaccess

愚蠢的是,我在没有查看链接的情况下发送了一份简报。其中一个坏了所以我想用htaccess处理这个。

我要链接的网址是:

http://www.domain.com.au/www.domain.com.au/campers-and-motorhomes/ne%20w-zealand/camper-rentals/

实际页面是: http://www.domain.com.au/campers-and-motorhomes/new-zealand/camper-rentals/

请注意新西兰的空间以及额外的www.domain.com.au

如何在htaccess中设置?

由于

1 个答案:

答案 0 :(得分:1)

由于您不必操纵网址,因此您可以使用简单的Redirect

Redirect /www.domain.com.au/campers-and-motorhomes/ne%20w-zealand/camper-rentals/  http://www.domain.com.au/campers-and-motorhomes/new-zealand/camper-rentals/

编辑如果Apache不喜欢未引用%20的空格,请尝试使用真实空间引用整个内容:

Redirect "/www.domain.com.au/campers-and-motorhomes/ne w-zealand/camper-rentals/"  http://www.domain.com.au/campers-and-motorhomes/new-zealand/camper-rentals/

Edit2 如果它附加了一个查询字符串,你需要使用mod_rewrite来摆脱查询字符串,而不是一个简单的重定向,我担心。

RewriteEngine On
# If the request starts with www.domain.com.au, it is the broken link
# Rewrite to the proper URL and put ? on the end to remove the query string
RewriteRule ^www\.domain\.com\.au http://www.domain.com.au/campers-and-motorhomes/new-zealand/camper-rentals/? [L,R=301]