Forum Moderators: phranque

Message Too Old, No Replies

Rewrite subdomain to root?

Serve up files in 'public_html' to requests for 'subby.domain.com'

         

tigertom

5:55 pm on Jun 11, 2007 (gmt 0)

10+ Year Member



Setting up a subdomain involves setting up 'public_html/subdir'. Requests for 'subdir.domain.com' serve files from this subdirectory.

I want to serve files from my root 'public_html' directory when requests are made for 'subdir.domain.com'. I will use Server Side Includes to decide what content is served from 'index.html', for example.

i.e. I don't want the hassle of putting the same files in half a dozen subdirectories just so I can have some subdomains.

e.g.: I need mod_rewrite code like this to put in 'public_html/subdir', or something cleverer:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/(.*)$
RewriteRule ^(.*)$ /home/username/public_html/$1 [L]

I don't want a redirect. I want a rewrite.
This particular code gives an error. It's just an illustration.

PS: I don't have access to httpd.conf. Virtual Subdomains would also be nice, but I'd like a 'portable' solution, if I need to move servers in a hurry.

tigertom

9:56 pm on Jun 11, 2007 (gmt 0)

10+ Year Member



Found this elsewhere. A shell command:

ln -s /home/username/public_html /home/username/public_html/subdir

Makes a symbolic link between the two directories. Haven't tried it yet, as I'm still looking for a .htaccess solution.

tigertom

12:12 am on Jun 12, 2007 (gmt 0)

10+ Year Member



This seems to work:

First, at the shell prompt:

ln -s /home/username/public_html/ /home/username/public_html/subdir/

This creates a symbolic link to 'public_html' in 'subdir'. It looks like there's now a directory 'subdir/public_html'

[subdir.domain.com...] can now be called by the browser, but that looks cr*ppy, so:

Then create subdir/.htaccess

... and put in it:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} .*
RewriteRule .* /public_html/$1 [L]

[subdir.domain.com...] then serves up the index page in '/home/username/public_html'

I'm off to bed.

tigertom

7:59 pm on Jun 16, 2007 (gmt 0)

10+ Year Member



Postscript:

My webhost has a new version of Cpanel. I don't know whether I missed it before, but it looks like I could've just pointed all my subdomains to 'public_html' direct, without any of the jiggery-pokery above. Oh well.