SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 33
  1. #1
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)

    Best practices for blocking multiple entry paths to addon domain?

    Hello. I have 7 or so addon domains. To those that don't know this is a hostgator option to add more domains off your main domain. This is not a subdomain however the folder structure is still setup as if it was a subdomain. Its a Cpanel error that they need to fix.

    So there are three ways to get to the addon domain.

    addondomain.maindomain
    maindomain/subdomain
    subdomain

    In theory unless you have links floating around google wont ever see these. Thats not good enough for me. So whats the best way you think to redirect or block these alternate paths? I have the code I just need your thoughts on best practice. Should I block them altogether with robots.txt or should I instead 301 redirect them? And I guess I would have to do this on each site and not just the main domain right? Or am I missing a easier way?

    Thanks!
    Eric W

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,644
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    Eric,

    I'm a believer in the power of mod_rewrite so that's what I'd use. Using pseudo code:

    If {HTTP_HOST} is NOT subdomain
    AND the subdomain directory is requested
    Redirect to http://www.subdomain.com without the subdomain directory as a permanent redirect.

    In mod_rewrite code:

    Code:
    # in maindomain's DocumentRoot
    
    RewriteCond %{HTTP_HOST} !^(www\.)?subdomain\.com [NC]
    RewriteRule ^subdomain/(.*)$ http://www.subdomain.com/$1 [R=301,L]
    While you've crossed your addondomain and subdomain terms, I'm sure you know which is which. The only problem I can see would be if the subdomain requires SSL ... but that can be handled in the subdomain's DocumentRoot and/or scripts requiring SSL.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  3. #3
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    Eric,

    I'm a believer in the power of mod_rewrite so that's what I'd use. Using pseudo code:

    If {HTTP_HOST} is NOT subdomain
    AND the subdomain directory is requested
    Redirect to http://www.subdomain.com without the subdomain directory as a permanent redirect.

    In mod_rewrite code:

    Code:
    # in maindomain's DocumentRoot
    
    RewriteCond %{HTTP_HOST} !^(www\.)?subdomain\.com [NC]
    RewriteRule ^subdomain/(.*)$ http://www.subdomain.com/$1 [R=301,L]
    While you've crossed your addondomain and subdomain terms, I'm sure you know which is which. The only problem I can see would be if the subdomain requires SSL ... but that can be handled in the subdomain's DocumentRoot and/or scripts requiring SSL.

    Regards,

    DK
    Ha i was like "where?!". Ya I see it so I did. maindomain/addondomain it should be. I don't think I have ever written anything 100% correct the first time I write it. I always have to catch it in the proof.

    Thanks for your reply So I have this canonical code in my htaccess which I believe your provided for me a while back. Using the redirect you showed above, would I also have to redirect all versions of non-www as well or would my existing code already provide that function? Looking closer at the code you just showed it looks like it does the non-www too is that correct?

    Code:
    # 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]

  4. #4
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Also. I do not want Google thinking by mistake that any of the subdomains are in anyway associated with the maindomain. Brains a bit rusty so I must confirm? If using either robot.txt blockage and 301 redirect Google cannot read those redirects correct? Forinstance it makes me parinoid to even have one of those redirects in my maindomains htaccess. From what I know/think is that any rediirection happens before google spiders can get their eyes on it correct? I just need to be 100% correct on this. Thats why I was thinking of a strait blockage with the robot.txt - like saying it doesnt even exist.

    EDIT - actually I think htaccess redirects happen before google can see it. But robot.txt google does read but honors what it reads. So how can it honor it if it doesnt read it. Thats my guesstament anyway. This guy gives his perspective on it http://smepals.com/google-panda/when...a-seo-recovery

  5. #5
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)

    Best practices for blocking multiple entry paths to addon domain?

    Actually it may just give me give me piece of mind to simply get another hosting server for 70 bucks a year to host all my additional domains. I will entertain the idea.

  6. #6
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    ...and additionally I seee you say put that code in the maindomains htaccess. It doesnt need to go in all the addondomains htaccess as well???

  7. #7
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,644
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    PT,

    Sounds like something I'd do! No worries.

    The code I used above made the www optional so that's already handled (and does not force www on the non-www'd version).

    Code:
    # Rewrite index.html/php to folder - First line excludes Forum
    RewriteCond $1 !^forum/adm(?:$|/)
    RewriteRule ^(.*/)?index\.(html?|php)$ /$1 [R=301,L]
    
    All that optional? Why not simply: RewriteCond %{REQUEST_URI} !(forum|adm) RewriteRule ([a-z]+/)index\.(html?|php)$ $1 [R=301,L] Please remember that I'm allergic to (.*) unless you want to capture EVERYTHING/NOTHING. htm, html and php?!?
    # 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]
    Why exclude forum and admin? Why the extraneous regex?
    Where's the redirection of the addondomain in all this?

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  8. #8
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,644
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    PT,

    That's why you'd redirect TO the addondomain(s)! Google (et al) should read the 301 redirects - that's what they're there for!

    I'm glad you've got more money (than sense?!?). Use mod_rewrite to resolve this very simply.

    Not necessary for maindomain/addondomain but, if addondomain.maindomain physically goes directly to maindomain/addondomain as its DocumentRoot, YES (I'd overlooked that possibility - good pick-up!).

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  9. #9
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    PT,

    That's why you'd redirect TO the addondomain(s)! Google (et al) should read the 301 redirects - that's what they're there for!

    I'm glad you've got more money (than sense?!?). Use mod_rewrite to resolve this very simply.

    Not necessary for maindomain/addondomain but, if addondomain.maindomain physically goes directly to maindomain/addondomain as its DocumentRoot, YES (I'd overlooked that possibility - good pick-up!).

    Regards,

    DK
    I didn't have your add on domain code in there that's all. Sense?!?! So you think that it would be stupid to buy new hosting account?

    "Not necessary for maindomain/addondomain but, if addondomain.maindomain physically goes directly to maindomain/addondomain as its DocumentRoot, YES (I'd overlooked that possibility - good pick-up!)."

    I didn't know I picked it up lol. So would your code you showed before differ now if that's the case! Thanks bro for your help.

  10. #10
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,644
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    PT,

    No, not stupid! Just rich! Solving an easy problem by throwing money at it when it's not needed is what I was commenting on. That would have been an easy solution but, as I said, it's just not necessary.

    Well, your question DID pick it up and you got kudos for that - deservedly so. I know better than to overlook things like that (DocumentRoot's physical location is important!).

    Yes, it should work (unless there are other things "under the hood" that I'm not aware of). Using RewriteCond statements to examine the {HTTP_HOST} can solve domain name problems when there are several domains using the same webspace (e.g., it helps me to change from US$ to NZ$ as appropriate within a script).

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  11. #11
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    PT,

    Sounds like something I'd do! No worries.

    The code I used above made the www optional so that's already handled (and does not force www on the non-www'd version).

    Code:
    # Rewrite index.html/php to folder - First line excludes Forum
    RewriteCond $1 !^forum/adm(?:$|/)
    RewriteRule ^(.*/)?index\.(html?|php)$ /$1 [R=301,L]
    
    All that optional? Why not simply: RewriteCond %{REQUEST_URI} !(forum|adm) RewriteRule ([a-z]+/)index\.(html?|php)$ $1 [R=301,L] Please remember that I'm allergic to (.*) unless you want to capture EVERYTHING/NOTHING. htm, html and php?!?
    # 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]
    Why exclude forum and admin? Why the extraneous regex?
    Where's the redirection of the addondomain in all this?

    Regards,

    DK
    I found the original thread where I got that conocalzation code. You were in it (the first post) but it looks like Jeff mot finished it up. http://www.sitepoint.com/forums/show...es-code-please.

    So how would you clean up or better that code? I had to remove the forum from it because otherwise I couldn't get into the admin page. Apparently it writes to the index page. So if I redirect to folder then no more index page to write to. I'm not appossed to doing it your way with regards to the addon domain. Still tooling around with how to proceed. If I were to buy two accounts and pay three years on advance then it actually comes to the same price I'm paying now.

  12. #12
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,644
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    PT,

    Jeff and I have a severe difference of opinion about many things so, if he's in a thread, I'll leave. For the most part, though, he does give good information.

    How would I clean-up the code? Since my mind (at least in the forum) is like a web page (stateless - I need to be refreshed every time), I'll just comment on the block of code (again) and await a full "specification" and the mod_rewrite code you're trying to use:

    Code:
    # .htaccess in DocumentRoot
    
    # First task - force www on the domain - I'll include the forum and adm, though, for URI consistency 
    
    # Rewrite non-www (non-canonical) to www - First line excludes Forum
    RewriteCond $1 !^forum/adm(?:$|/)
    # $1 is the {REQUEST_URI} variable so I'd use that instead
    # (?:$|/) 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)
    # Note, though, that this would PREVENT the force-www if forum or adm are requested which breaks your standardization
    #      so I'd recommend just dropping this RewriteCond entirely
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    # Perfect - unless you have subdomains which could then be redirected to www.subdomain.domain.com
    #      so I would recommend using your domain name after the "\." - be sure to keep the No Case flag, though!
    RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
    # Minor point but, again, (.*) is the ALL or NOTHING which happens to be Apache's {REQUEST_URI} variable so I'd simplify and use
    # RewriteRule .? http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    
    # SECOND Task: Strip index.{whatever} from the URI
    # Note, please, that your SysAdmin may have setup Apache to display the DirectoryIndex
    #       even when it's not requested ... you can't fight City Hall and you can't overrule httpd.conf!
    
    # Rewrite index.html/php to folder - First line excludes Forum
    RewriteCond $1 !^forum/adm(?:$|/)
    # Ditto the above
    # RewriteCond %{REQUEST_URI} !^(forum|adm) # recommended
    RewriteRule ^(.*/)?index\.(html?|php)$ /$1 [R=301,L]
    # Will you accept ANY characters before index.{whatever}? If not (and you're only using lowercase letters)
    # RewriteRule ([a-z]+/)+index\.(html?|php)$ $1 [R=301,L]
    I hope you're half as concerned about your website's security as I am about mine. If so, you'll not use wildcards indiscriminately and either specify the acceptable names ( like (forum|adm) ) or characters ( like [-a-zA-Z0-9_/]+ for hyphens, upper and lowercase letters, digits, underscores and slashes ). If you have a tool as powerful as mod_rewrite to help. Just don't let your scripts scrimp on similar checks, though!

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  13. #13
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    PT,

    Jeff and I have a severe difference of opinion about many things so, if he's in a thread, I'll leave. For the most part, though, he does give good information.

    How would I clean-up the code? Since my mind (at least in the forum) is like a web page (stateless - I need to be refreshed every time), I'll just comment on the block of code (again) and await a full "specification" and the mod_rewrite code you're trying to use:

    Code:
    # .htaccess in DocumentRoot
    
    # First task - force www on the domain - I'll include the forum and adm, though, for URI consistency 
    
    # Rewrite non-www (non-canonical) to www - First line excludes Forum
    RewriteCond $1 !^forum/adm(?:$|/)
    # $1 is the {REQUEST_URI} variable so I'd use that instead
    # (?:$|/) 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)
    # Note, though, that this would PREVENT the force-www if forum or adm are requested which breaks your standardization
    #      so I'd recommend just dropping this RewriteCond entirely
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    # Perfect - unless you have subdomains which could then be redirected to www.subdomain.domain.com
    #      so I would recommend using your domain name after the "\." - be sure to keep the No Case flag, though!
    RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]
    # Minor point but, again, (.*) is the ALL or NOTHING which happens to be Apache's {REQUEST_URI} variable so I'd simplify and use
    # RewriteRule .? http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    
    # SECOND Task: Strip index.{whatever} from the URI
    # Note, please, that your SysAdmin may have setup Apache to display the DirectoryIndex
    #       even when it's not requested ... you can't fight City Hall and you can't overrule httpd.conf!
    
    # Rewrite index.html/php to folder - First line excludes Forum
    RewriteCond $1 !^forum/adm(?:$|/)
    # Ditto the above
    # RewriteCond %{REQUEST_URI} !^(forum|adm) # recommended
    RewriteRule ^(.*/)?index\.(html?|php)$ /$1 [R=301,L]
    # Will you accept ANY characters before index.{whatever}? If not (and you're only using lowercase letters)
    # RewriteRule ([a-z]+/)+index\.(html?|php)$ $1 [R=301,L]
    I hope you're half as concerned about your website's security as I am about mine. If so, you'll not use wildcards indiscriminately and either specify the acceptable names ( like (forum|adm) ) or characters ( like [-a-zA-Z0-9_/]+ for hyphens, upper and lowercase letters, digits, underscores and slashes ). If you have a tool as powerful as mod_rewrite to help. Just don't let your scripts scrimp on similar checks, though!

    Regards,

    DK
    Unfortunately my skills here arent good enough to know the answers to any questions above or to edit them appropriately.

  14. #14
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    I sort of convoluted this thread a bit. But just to confirm, since you mentioned a caught a over site, is this following code all I would need to redirect the addon domain from all the different entry paths? And wouldnt I also have to put said code in the main site and the addon domains htaccess's? Thanks!

    Code:
    # in maindomain's DocumentRoot
    
    RewriteCond %{HTTP_HOST} !^(www\.)?subdomain\.com [NC]
    RewriteRule ^subdomain/(.*)$ http://www.subdomain.com/$1 [R=301,L]

  15. #15
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    OK i just tried using this but it seemed to have no effect - still went to the site via the additional paths.

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

    Strangley even before I put in the htaccess code I could only get to it via two paths

    http://addondomain.com/ (As an Addon Domain Name)
    http://primarydomain.com/addondomain.com/ (As a subfolder)

    http://addondomain.com.primarydomain.com/ (As a Subdomain Name) would come back as a 404. Am I missing something?

  16. #16
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,644
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    PT,

    I tried to be "too cute" with my use of maindomain's DocumentRoot for the majority of the mod_rewrite work for subdomain. Upon reconsideration, it would be simpler to do as you suggested and put all the mod_rewrite in the subdomain's DocumentRoot (where you don't need to worry about other subdomains).

    Code:
    # 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]
    Since you're no longer concerned with conflicts with maindomain or any other subdomain, this is by far the simplest (and most effective) approach.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  17. #17
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Cool thank you I will try that. Any idea why my addon domain is not assessable via http://addondomain.com.primarydomain.com/. Is it maybe because of the non cononcol link code I have in there that I referenced above in the beginning?

  18. #18
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Also what are your thoughts on mod_rewrite vs 301 redirect for this purpose? Rewrite seems to me better suited.

  19. #19
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,644
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    PT,

    Quote Originally Posted by PicnicTutorials View Post
    Cool thank you I will try that. Any idea why my addon domain is not assessable via http://addondomain.com.primarydomain.com/. Is it maybe because of the non cononcol link code I have in there that I referenced above in the beginning?
    The obvious reason is that the subdomain URL for addondomain will not have two .com's in it.

    Quote Originally Posted by PicnicTutorials View Post
    Also what are your thoughts on mod_rewrite vs 301 redirect for this purpose? Rewrite seems to me better suited.
    301 is a type of redirect which is available to both mod_rewrite and mod_alias (which is what you're trying to compare it with). For me, mod_rewrite has a lot more power (it can use RewriteCond statements to check Apache variables other than the URI) while mod_alias (at least the Redirect function) does not require regular expressions (not loading the regex engine makes mod_alias faster for simple redirections). I will use both (an early thing you should learn about mod_rewrite is when NOT to use it) as required by the situation but, with a knowledge of the simple regex used by mod_rewrite, it's such a powerful tool that I tend to lean on it as if it's a crutch (I KNOW it works!).

    Oh? "... for this purpose"? mod_alias can't examine the {HTTP_HOST} so it's not even in the running.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  20. #20
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    PT,

    I tried to be "too cute" with my use of maindomain's DocumentRoot for the majority of the mod_rewrite work for subdomain. Upon reconsideration, it would be simpler to do as you suggested and put all the mod_rewrite in the subdomain's DocumentRoot (where you don't need to worry about other subdomains).

    Code:
    # 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]
    Since you're no longer concerned with conflicts with maindomain or any other subdomain, this is by far the simplest (and most effective) approach.

    Regards,

    DK
    You just mixed up terms here like I did right? I assume it matters zero in the end code? Sorry to be obsessive it's just url rewrites are so important I have to be 10%.

    Oh and I did try it without the .com http://addon.maindomain.com as well. Just 404.

  21. #21
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    100%

  22. #22
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,246
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by PicnicTutorials View Post
    Unfortunately my skills here arent good enough to know the answers to any questions above or to edit them appropriately.
    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.
    "First make it work. Then make it better."

  23. #23
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jeff Mott View Post
    Here's the alternate views on those.



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



    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?

    Code:
    # 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!

  24. #24
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,246
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    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?
    "First make it work. Then make it better."

  25. #25
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,656
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Code:
    # 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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •