Forum Moderators: phranque

Message Too Old, No Replies

Redirecting root visitors while allowing subdirectory access

With using the .htaccess file

         

Jeremy_H

3:50 am on Apr 26, 2006 (gmt 0)

10+ Year Member



If somebody tries to go to the root of my domain.com I would like to direct them elsewhere. Therefore I have used the following line in my .htaccess file:

redirect 301 / [elsewhere.com...]

However, I would like to let people visit sudirectories of my site, such as:

[domain.com...]
[domain.com...]
[domain.com...]

Unfortunately, as is now, they all get redirected to:

[eleswhere.com...]
[eleswhere.com...]
[eleswhere.com...]

I tried playing around with my .htaccess code, to something like this:

redirect 301 /index.html [elsewhere.com...]

But it doesn't work.

Any ideas?

I know I can create an index file that will redirect the user, but I really wanted to do it correctly, and in the .htaccess file.

jdMorgan

1:22 pm on Apr 26, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



See RedirectMatch [httpd.apache.org]. The Redirect directive uses prefix-matching, so any requested URL starting with the given prefix ("/" or "/index.html" in your case) will be redirected. So that is why your code won't do what you want.

RedirectMatch allows you to specify an exact match, using regular expressions.

Jim

Jeremy_H

1:31 am on Apr 27, 2006 (gmt 0)

10+ Year Member



Thanks Jim,

That explains the problems I was having, and it looks like RedirectMatch is the way to go.

Thanks again.