Forum Moderators: phranque

Message Too Old, No Replies

Redirecting Wildcard Subdomains outside the main site's base

redirecting a wildcard subdomain to outside the main site's base

         

hachque

8:13 am on Apr 2, 2007 (gmt 0)

10+ Year Member



I want to redirect as follows :

www.mysite.com -> /srv/www/www/
abc.mysite.com -> /srv/www/abc/
absolutlyanythingcangohere.mysite.com -> /srv/www/anditllredirecttothedirectoryhere

All the mod_rewrite examples I've seen do something like this :

www.mysite.com -> /srv/www/htdocs/
abc.mysite.com -> /srv/www/htdocs/abc/
absolutlyanythingcangohere.mysite.com -> /srv/www/htdocs/anditllredirecttothedirectoryhere

having the subdomains pointing to directories inside the main site, however I want the subdomains to point outside the main site as in the first example above.

jdMorgan

6:37 pm on Apr 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You may not internally rewrite above the DocumentRoot configured in your VirtualHost container. You may externally redirect to any other domain you like, but of course this is "exposed" to the visitor, who sees the change in his/her browser address bar.

Jim

hachque

11:14 pm on Apr 2, 2007 (gmt 0)

10+ Year Member



Could I use :

<VirtualHost *:80>
DocumentRoot /srv/www
ServerName mysite.com
ServerAlias *.mysite.com
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain\.com
RewriteRule (.*) [mydomain.com...] [R=301,L]
RewriteCond %{http_host} .
RewriteCond %{http_host} ^([^.]+)\.mydomain.com [NC]
RewriteRule ^(.*) [mydomain.com...] [R=301,L,QSA]
</VirtualHost>

I can't test it right now because my system won't point to the DNS server I have running on my local system.

jdMorgan

11:58 pm on Apr 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have to ask: Why do you want to externally redirect, exposing the subdirectory to the visitor, instead of rewriting internally, or -better yet- simply declaring a separate VirtualHost container for all except "mydomain.com"?

Jim

hachque

3:37 am on Apr 3, 2007 (gmt 0)

10+ Year Member



Because I really want it to point to the users home directory then under htdocs.

Like :

www.mysite.com -> /home/thisuserownsthissite/www/htdocs/
abc.mysite.com -> /home/thisuserownsthissite/abc/htdocs/
ddd.mysite.com -> /home/someoneelseownsthisone/ddd/htdocs/
absolutlyanythingcangohere.mysite.com -> /home/andthisuserownsthisone/anditllredirecttothedirectoryhere/htdocs/

jdMorgan

1:47 pm on Apr 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Take a hard look at Apache mod_userdir. This may do what you want, without all the security problems inherent in using a redirect to solve this problem. Additionally, it allows you to enable and disable users in a convenient way.

Jim