Forum Moderators: phranque
domain.com/sites/sub1 -> sub1.domain.com
domain.com/sites/sub2 -> sub2.domain.com
domain.com/sites/sub3 -> sub3.domain.com
My .htaccess used to make this flow work but for some reason when the host upgraded everything went haywire. Old script below:
RewriteEngine on
RewriteCond %{HTTP_REFERER}!^http://domain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://domain.com$ [NC]
RewriteCond %{HTTP_REFERER}!^http://sub2.domain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://sub2.domain.com$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.domain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.domain.com$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.sub2.domain.com/.*$ [NC]
RewriteCond %{HTTP_REFERER}!^http://www.sub2.domain.com$ [NC]
Don't know if somehow I have overwritten the old .htaccess but this is the format that is left on the server.
Can someone enlighten me on the correct way to structure this.
move root to root/sites/
and place .htaccess under sites so that all sub-domains will have something like:
domain.com/sites/subdomain1 -> subdomain1.domain.com
but if it's done like that won't it mess up the main site on the root domain.com/index.*
I'm hessitant to try it and mess things up again. Gambling on the chips and bits from the threads wish me luck*
I'm following this as my bible: [webmasterworld.com...]
The normal method for mapping subdomains to subdirectories is to:
This is tricky, because it might easily result in an 'infinite' redirect-rewrite loop if you don't take steps to prevent it.
You must use {THE_REQUEST} to distinguish between direct client requests for /sites/sub1/* from the internal requests for that subdirectory that result from the internal rewrite.
I'll show you some example code, but only if you promise to make and maintain backups of your critical files from now on... :)
# Externally redirect direct client requests for example.com/sites/<subdomain> back to <subdomain>.example.com
# (Prevents duplicate-content problems and discourages users from poking around in the file system)
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /sites/
RewriteRule ^sites/([^/]+)/(.*)$ http://$1.example.com/$2 [R=301,L]
#
# Internally rewrite <subdomain>.example.com requests to /sites/<subdomain> subdirectory
# Don't rewrite to /sites if we've already rewritten (prevents a rewriting loop)
RewriteCond $1 !^sites/
# Exclude main domain and its www subdomain from this rewrite
RewriteCond %{HTTP_HOST} !^(www\.)?example\.com
# Get subdomain to %1 variable
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com
# Internally rewrite <subdomain> to /sites/<subdomain> subdirectory
RewriteRule (.*) /sites/%1/$1 [L]
As for your anti-hotlinking code, I don't know what the RewriteRule was, so I can't help you there. But I will caution you NOT to use cPanel functions which add code to .htaccess -- cPanel simply writes awful, inefficient code, and can slow down your server. Either study-up on the Apache directives available in .htaccess and code it yourself, or consider doing without those functions...
Jim