Fraser
Fraser

Reputation: 14246

htaccess redirect url with space in it

Stupidly, I have sent out a newsletter without checking the links. One of which is broken so I want to handle this with htaccess.

My URL that is being linked to is:

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

where the actual page is: http://www.domain.com.au/campers-and-motorhomes/new-zealand/camper-rentals/

Note the space in new zealand as well as the additional www.domain.com.au

How can I set this up in htaccess?

Thanks

Upvotes: 1

Views: 1873

Answers (1)

Michael Berkowski
Michael Berkowski

Reputation: 270599

Since you don't have to manipulate the URL, you can use a simple 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/

Edit If Apache doesn't like the space unquoted as %20, try quoting the whole thing with a real space in there:

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 If it's appending a query string, you will need to use mod_rewrite to get rid of the querystring rather than a simple redirect, I'm afraid.

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]

Upvotes: 1

Related Questions