Gossamer Forum
Home : General : Internet Technologies :

Question with mod_rewrite?

Quote Reply
Question with mod_rewrite?
I have domain.com and sub.domain.com
The root path of domain.com is /path/to/root
The root path of sub.domain.com is /path/to/root/sub

Because of this path configuration a user can type www.domain.com/sub but they get a 403 error.

How can I avoid that? So if a user types www.domain.com/sub is redirected to sub.domain.com instead of a 403 error? Can I do this with mod_rewrite? How?
Thank you very much
Max
The one with Mac OS X Server 10.4 :)
Quote Reply
Re: [maxpico] Question with mod_rewrite? In reply to
RewriteEngine On
RewriteRule ^/sub(/.*)?$ http://sub.domain.com$1 [L,R]

...I guess something like that, although not tested.

Last edited by:

Paul: Mar 23, 2003, 1:55 AM
Quote Reply
Re: [Paul] Question with mod_rewrite? In reply to
I don't think that will work because I want that only if a user types www.domain.com/sub is redirected to sub.domain.com Unsure
Max
The one with Mac OS X Server 10.4 :)
Quote Reply
Re: [maxpico] Question with mod_rewrite? In reply to
I'm not sure what you mean....that's what the redirect rule above does.
Quote Reply
Re: [Paul] Question with mod_rewrite? In reply to
I mean that this might not be the solution as when a user access from http://sub.domain.com the server should not redirect him because he's already in the right place..

However I wrote an .htaccess file in /path/to/root with this line:

Redirect permanent /sub http://sub.domain.com

This seems to work... Do you think this setup is OK and with no cons?
Thanks
Max
The one with Mac OS X Server 10.4 :)
Quote Reply
Re: [maxpico] Question with mod_rewrite? In reply to
Yeah that should be ok. As for my rewrite, I may be wrong but I think it should work as you want. If the user is already at sub.domain.com then it won't redirect as it only redirects in the URL matches /sub (not including the domain itself so it won't match http://sub)
Quote Reply
Re: [Paul] Question with mod_rewrite? In reply to
Fine Sly
Max
The one with Mac OS X Server 10.4 :)