1

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

1 Answer 1

1

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] 
Sign up to request clarification or add additional context in comments.

5 Comments

Thank you. I'm a total novice at htaccess, does this need to go in the <IfModule mod_rewrite.c> block or can it just sit by itsself?
@Fraser Technically it's part of mod_alias so you can wrap it in side <IfModule mod_alias.c>, but that probably isn't necessary since mod_alias is just about always installed and enabled.
Thanks again. Unfortunately it's not picking up the page. It seems to be the space throwing it off (the redirect works with other URLs without a space). I've tried escaping it with \ but this gives me an internal server error. Any ideas?
I managed to get it to pick the page up by swapping %20 with a space and putting the URL in quotation marks however it is now redirecing with a huge querystring of the original url which is breaking the page. How can I remove the querystring?
You are my hero. Thank you Michael. Very much appreciated

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.