Can mod_rewrite access symlink information?

Using a single web hosting account to host multiple sites

Can mod_rewrite access symlink information?

Postby spike21 » Mon Dec 08, 2008 7:12 pm

Hi there, I've done the typical mass virtual host setup where there is one virtual host directive that directs traffic for a request to the folder that matches the domain name. To handle domain aliases I created symlinks for those domains pointing to the main domain folder.

That all works well but I wonder if mod_rewrite can access the intended destination of a symlink and then redirect the user to that address (so their browser bar updates with the official address). We'd also then be able to tell google that this is a permanant redirect.

Is this possible with mod_rewrite?

Cheers,

Brendon
spike21
 
Posts: 3
Joined: Mon Dec 08, 2008 6:58 pm

Postby richardk » Tue Dec 09, 2008 12:25 pm

There might be an environmental variable set, but i don't know of it. It is also unlikely to be set in the <VirtualHost> where you could redirect globally.

I think the only solution will be to put a .htaccess file in each document root
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby spike21 » Tue Dec 09, 2008 6:38 pm

That sounds promising :) At least then there's no need to keep a list of aliases, just the original url.

Would it be possible to even read this from the folders name (the folder containing the .htaccess file)? This would then make it truely low maintenance :)

Brendon
spike21
 
Posts: 3
Joined: Mon Dec 08, 2008 6:58 pm

Postby richardk » Wed Dec 10, 2008 7:57 am

Only if there is an environmental variable with the "real" directory name in it. I think SCRIPT_FILENAME has the symlink directory name.

If you have PHP you could use phpinfo to see what variables are available. Or for Perl - Printing all CGI environment variables. I'm sure there is similar for all other languages.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby spike21 » Thu Dec 11, 2008 1:38 pm

Thanks Richard, that gives me something to go on. I'll let you know how I get on :)

Cheers,

Brendon
spike21
 
Posts: 3
Joined: Mon Dec 08, 2008 6:58 pm


Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 13 guests

cron