2012-07-12 31 views
1

很愚蠢的是,我發送了一條通訊,沒有檢查鏈接。其中一個是壞的,所以我想用htaccess來處理這個問題。htaccess重定向url中的空格

我是被鏈接到網址是:

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

既然你沒有操縱URL,你可以使用一個簡單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] 
+0

謝謝。我是htaccess的總新手,是否需要進入塊,還是隻能坐在自己的位置? – Fraser 2012-07-12 01:55:20

+1

@Fraser從技術上講,它是mod_alias的一部分,所以你可以將它封裝在''的一側,但這可能不是必須的,因爲mod_alias只是總是安裝並啓用。 – 2012-07-12 01:56:28

+0

再次感謝。不幸的是,它沒有拿起頁面。它似乎是拋出它的空間(重定向與沒有空間的其他URL一起工作)。我嘗試用\轉義它,但這給我一個內部服務器錯誤。有任何想法嗎? – Fraser 2012-07-12 02:02:05