Best practices for blocking multiple entry paths to addon domain?

100%

Here’s the alternate views on those.

$1 is the {REQUEST_URI} variable so I’d use that instead

Sometimes this doesn’t matter one way or the other. But when it does matter, there are drawbacks and no benefits. More details.

(?:$|/) is some weird regex - it appears to try to match an end of string OR / (with possible other information behind it, i.e., no end anchor). I’d simply use RewriteCond %{REQUEST_URI} !^(forum|adm)

Some example URLs that we want to match with this pattern are:

forum/adm
forum/adm/yada

And an example URL that shouldn’t match is:

forum/admyada

The alternatively suggested pattern will indeed correctly match the first two, but it will also incorrectly match the third. To make sure we match the first two but not the third, we need to match “forum/adm” followed by either the end of the string or a slash.

In an effort to save time (cut out the middle man - me) can you show me Jeff how you would put this together?

# in SUBdomain's DocumentRoot
RewriteCond %{HTTP_HOST} !^(www\\.)?subdomain\\.com$ [NC]
# Note: Only requests of the subdomain, even via maindomain, will have access to the subdomain directory
RewriteRule .? http://www.subdomain.com/$1 [R=301,L]

Thanks!

Well, the “best practice” would probably be to not have the subdomains or addondomains as a subdirectory of the maindomain. It would simplify so so much. And if Hostgator doesn’t let you do that, then I would dump Hostgator.

But in the meantime… to make sure I understand correctly, if the user or google tries to access the addondomain directory from the maindomain, then you want that to be redirected/forbidden/404?

Earlier, you said you tried this:

RewriteCond %{HTTP_HOST} !^(www\.)?myaddondomain\.com [NC]
RewriteRule ^myaddondomain/(.*)$ http://www.myaddondomain.com/$1 [R=301,L]

But it didn’t do anything? At a glance, it looks like it should work just fine, so there must be something else interfering. Do you have htaccess files and rewrite rules inside the addondomain directory?

# UTF-8 encoding and English language all file extensions
AddDefaultCharset utf-8
AddCharset utf-8 .php .html .css .js .xml
DefaultLanguage en-US

# mod_rewrite On only needed once
RewriteEngine On

# Rewrite index.html/php to folder - First line excludes Forum
RewriteCond $1 !^forum/adm(?:$|/)
RewriteRule ^(.*/)?index\\.(html?|php)$ /$1 [R=301,L]

# Rewrite non-www (non-canonical) to www - First line excludes Forum
RewriteCond $1 !^forum/adm(?:$|/)
RewriteCond %{HTTP_HOST} !^www\\. [NC]
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]

# Compress Files
<FilesMatch "\\.(js|css|html|php|xml)$">
SetOutputFilter DEFLATE
</FilesMatch>

# Turn off ETags
Header unset ETag
FileETag None

# Cache Files 30 Days
<filesMatch "\\.(php|html|css|js|swf|pdf|xml|mp3|gif|jpg|png)$">
ExpiresActive On
ExpiresDefault "access plus 30 days"
Header append Cache-Control "public"
</filesMatch>

There is my htaccess in the addondomain. The main has the same give or take. Ya just redirecting. Because as is the addon domain is treated like a sub and can be accessed 3 ways ( six including www and non). It’s not hostgator persay. It’s cpanel. They are all like that. Is there any other back end ( like plesk) that does addons differnt? I was seeing where this thread took me before I desided if I was going to put them all on separate cpanels/IPS.

Ahh. Since you have more rewrite rules in your addon directory, you’ll have to put this new rewrite rule in there as well, instead of in your root.

RewriteCond %{HTTP_HOST} !^(www\.)?myaddondomain\.com [NC]
RewriteRule ^(.*)$ http://www.myaddondomain.com/$1 [R=301,L]

Don’t want to step on anybody’s toes here. Just trying to get to the bottom with the best code. So here are the two versions I have been given in here thread. Can you Jeff please explain to me (possibly again) why your couple different characters are better than the previous version I was given above? They are both basically the same eccept a couple little characters. Thank you sir.

RewriteCond %{HTTP_HOST} !^(www\\.)?addondomain\\.com$ [NC]
RewriteRule .? http://www.addondomain.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} !^(www\\.)?addondomain\\.com [NC]
RewriteRule ^(.*)$ http://www.myaddondomain.com/$1 [R=301,L]

And Jeff I respect your opinion. Do you think it would be prudent to put this single domain (the only one that puts food on my table) in its own cpanel. And then just put all my other addon domains into another hosting account? The only benefit being being 100% sure there were never any mix ups as to which sub folders belong to which domain. Being that addon domains are treated as sub domains is is remotely possible google carried some site juice from one to the other. And one in particular I don’t want ever associated with my main domain. In any way. Thanks!

Well, for starters, I suspect there was a typo in what dklynn posted. He probably meant to write this:

RewriteRule .? http://www.addondomain.com%{REQUEST_URI} [R=301,L]

So the difference is the FONT=Courier New/$1[/FONT] vs .?/%{REQUEST_URI}. My thoughts about that are above in post #22.

Paying for two hosts seems like a bit of a waste. Personally, I’d rather have a host that let’s me pick where each domain, subdomain, and addondomain will live in the filesystem. And if HostGator doesn’t let you do that…

That being said, I did some quick googling, and it looks like HostGator does let you pick where the subdomains/addondomains will live – http://support.hostgator.com/articles/cpanel/please-read-before-creating-a-subdomain. It sounds as though /public_html/{subdomain} is only a suggested location, and you can actually set the document root to anywhere.

Looks like this in the coments is what your talking about. Interesting I’ll have to confirm what that means. You now what that means?

QUESTION
"Is it possible to have a seperate document-root for the subdomain which is NOT in the document root of the main-domain?

If not, how can I protect the directory to make it accessible as subdomain.domain.com and not accessible trough domain.com/subdomain?"

ANSWER
"Yes, what you propose will work. I do that often with my Addon domains.

Just create the domain as normal, but in the Document Root path, remove “public_html/” and just type the folder name. The root folder will appear outside of public_html."

I got the answer…

You cannot change the document root of the primary domain, as stated in the “Document Root Changes” article.

However, I have an advanced trick for you! When you create your addon domains, choose the Document Root for those to be outside of public_html (erase “public_html/”).

EXAMPLE:
New Domain Name: addondomain.com
Document Root: public_html/addondomain.com

Change that to…
Document Root: addondomain.com

Now when you create it, the addon domain cannot be seen as part of the primary domain, even by those who know the site structure.

But you wrote

RewriteRule .? http://www.addondomain.com/$1 [R=301,L]

So should I that or this

RewriteRule .? http://www.addondomain.com%{REQUEST_URI} [R=301,L]

The first one is what dklynn wrote. The second one is what dklynn probably meant to write. And then this one is mine…

RewriteRule ^(.*)$ http://www.myaddondomain.com/$1 [R=301,L]

It means that your subdomains/addondomains don’t need to live inside your maindomain.

Ya I got it. Thank I did not know that. From what I can tell it would just prevent the addon from being accessed via main/addon. May addon.main too I guess. I’ll have to talk to histgator about this .