Htaccess redirect to main site, discarding rest


#1

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. :stuck_out_tongue:


#2

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: [color=#6600CC]Atropos[/color] | openvein.org


#3

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. :slight_smile:


#4

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.


If you want useful replies, ask smart questions.