Forum Moderators: Robert Charlton & goodroi
My host lists all my additions sites as sub-domains of my primary site. for example my main site is main.com and my second site is second.com but I can access the second site with this url also: second.main.com.
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule ^(.*)$ http://www.example.com/$1? [R=301,L]
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1? [R=301,L]
hosting companies started offering it as a way for people like me with shared hosting accounts to host several sites within the same basic account at the same price as one site
First way: you've got one directory, which is your domain. If you get additional domains, they're directories within the main one. This happens to be also the most common physical setup for subdomains. But you can't really put "subdomain" and "internal file system" into the same sentence, because servers don't have four dimensions. Conversely, you could have a subdomain living on an entirely different server.
Second way: each person has a "userspace", represented by one directory somewhere in the filesystem. Within that userspace are parallel directories for one or more domains. This means, among other things, that there can be an outer htaccess covering all domains, and then individual htaccess for single domains. htaccess is governed strictly by physical filepaths. A request either does or does not pass through a given directory; there are no side doors. You'd know if requests for one site were passing through a different site's htaccess.
but it's not how they do it.
the server has to be configured to fetch files from the right directory or subdirctory
My host lists all my additions sites as sub-domains of my primary site. for example my main site is main.com and my second site is second.com but I can access the second site with this url also: second.main.com.
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1? [R=301,L]
I would (and do) use an essentially-the-same ruleset as phranque's example:
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1? [R=301,L]
Which .htaccess file do you put that code in?
Options +FollowSymLinks
<Files .htaccess>
order allow,deny
deny from all
</Files>
order allow,deny
deny from 195.240.38.200
deny from 5.63.145.68
deny from 198.105.219.58
deny from 5.10.83.
allow from all
RewriteEngine On
RewriteCond %{HTTP_REFERER} \.(ru|ua|cn|pl|ro)(/|$) [NC]
RewriteRule .* - [F]
ErrorDocument 403 "Access Denied"
RewriteCond %{HTTP_HOST} ^primary\.com$ [NC]
RewriteRule ^(.*)$ http://www.primary.com/$1 [R=301,L]
ErrorDocument 404 /custom404.html
Options +FollowSymLinks
<Files .htaccess>
order allow,deny
deny from all
</Files>
RewriteEngine on
order allow,deny
deny from 195.240.38.200
deny from 5.63.145.68
deny from 5.10.83.
deny from 75.7.214.
allow from all
RewriteCond %{HTTP_REFERER} \.(ru|ua|cn|pl|ro)(/|$) [NC]
RewriteRule .* - [F]
ErrorDocument 403 "Access Denied"
RewriteEngine on
RewriteCond %{HTTP_HOST} ^add-on\.com$ [NC]
RewriteRule ^(.*)$ http://www.add-on.com/$1 [R=301,L]
ErrorDocument 404 /custom404.html
RewriteOptions inherit ErrorDocument 403 "Access Denied"
There is no way to bypass a physical folder. But if you don't say
RewriteOptions inherit
in the deeper htaccess files, then the results of any earlier RewriteRules are discarded as if they had never existed. Up to and including flat-out 403s. This is in the Apache docs but I've also experimented. That's probably why your outer and inner folders seem to function independently; you're seeing the special behavior of mod_rewrite.
There is no way to bypass a physical folder