htaccess redirect to main site, discarding rest

htaccess redirect to main site, discarding rest

Posted by: FruitFly
Posted on: 2007-03-11 11:26:00

I've moved a site over to a new system where we used to use a subdomain (sub.domain.com) - but now will be using the main domain instead AND the link structure will be very different. (I.E. it used to be http://sub.domain.com/blah/hegdt.html and now will be using a dynamic program...)

There are FAR too many pages for me to try to redirect each possibility, and we're changing a lot of the way it was structured anyway, so really, that's just not feasible. So, I basically want to redirect anyone who goes to *any* page under sub.domain.com to go to the MAIN page at www.domain.com - without carrying over any of the rest of the URL...

using the following in the subdomain's root htaccess:

Redirect / http://www.domain.com/

produces a redirect, but it tries to keep the whole URL (ex. http://sub.domain.com/blah/hegdt.html redirects to http://www.domain.com/blah/hegdt.html)

How can I tell it to just go to www.domain.com ?

Many thanks in advance... htaccess is not my strong point. :P

Re: htaccess redirect to main site, discarding res

Posted by: Atropos7
Posted on: 2007-03-11 19:44:00

Are you removing the content from the subdomain? Because you can use

ErrorDocument 404 http://example.com/

And then instead of getting a "Not found" the visitor will get a redirect.

Though you can also use

RedirectMatch .* http://example.com/





cool Atropos | openvein.org

Re: htaccess redirect to main site, discarding res

Posted by: FruitFly
Posted on: 2007-03-11 22:59:00

The ErrorDocument statement didn't work, but the RedirectMatch did!

Thanks so much... I looked all over the place for this. Just didn't know how to ask the search engines the right question to get the answer. :)

Re: htaccess redirect to main site, discarding res

Posted by: kchrist
Posted on: 2007-03-12 07:50:00

A much better approach would be to let the links result in a 404 but provide a helpful error page with an explanation, search form, and navigation and/or a sitemap. Everyone understands 404s, but being unexpectedly redirected somewhere else can be a little confusing. Better to handle the error gracefully than try to preempt it like this.

Tags: htaccess redirectwww domainblahsubdomainmany thanksbasicallythanks in advance