SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,658
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)

    Canonicalization index and no www to www with addon domains issue

    Morning

    So with some help I set this up a while back. It redirects/rewrites all index files to root and no www to www. I then found out that it was redirecting all my addon domains to www.maindomain.com/addondomain. I then added some fixes to it. BUT! Now if I don't have a index in the addon domain it redirects to www.maindomain.com/addondomain again. Is this normal behavior for said code? Or is there something amiss with the code? I need this fixed because I dont want google thinking any addon domains are subdirectories of the main domain. Thanks!

  2. #2
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,658
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    lol the code would be nice huh?

    # 301 permanent redirect index.html(htm) to folder with exclusion for addon domains
    RewriteCond %{HTTP_HOST} !(addondomain\.com|addondomain\.com|addondomain\.com|addondomain\.com|addondomain\.com)
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html?\ HTTP/
    RewriteRule ^(([^/]+/)*)index\.html?$ ht tp://w ww.maindomain.com/$1 [R=301,L]

    # 301 permanent redirect non-www (non-canonical) to www with exclusion for addon domains
    RewriteCond %{HTTP_HOST} !(addondomain\.com|addondomain\.com|addondomain\.com|addondomain\.com|websitecodetutorials\.com)
    RewriteCond %{HTTP_HOST} !^(www\.maindomain\.com)?$
    RewriteRule (.*) ht tp://w ww.maindomain.com/$1 [R=301,L]

    Note I put spaces in the main domain.

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

    I'll be back after football but your addon domains should NEVER see the .htaccess in your main account's root. It looked like you're using their subdirectories in your .htaccess though, so main domain requests WILL be affected (but only via the main domain).

    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

  4. #4
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,658
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    My add on domains arnt seeing the htacces. Only my main is. The htacces is in the main domain.

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

    Halftime ... then get rid of (comment out) the RewriteCond statements with the subdomains.com regex.

    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

  6. #6
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,658
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Not really sure what you mean. The us domain code currently in there prevents it from redirecting to main/addon regardless if index file is there or not.

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

    Specification:

    1. Redirects all index files (on maindomain.com) to DocumentRoot's index.html
    2. Enforce www on maindomain.

    There is no way that your .htaccess in the DocumentRoot of maindomain can ever be read for requests of any addondomain (so any reference to addondomain is ... well, silly).

    Since your addondomains ARE subdirectories of maindomain, you'll need to add code to each addondomain to enforce their stand-alone status.

    PLEASE wrap your code in [code]...[/code] tags as that preserves the code when quoting for a reply.

    Code:
    RewriteEngine on
    # Send subdomains off to their own domains so 
    # you don't need to worry about exclusions below
    RewriteCond %{HTTP_HOST} ^((www\.)?([a-z]+\.))maindomain\.com$ [NC]
    # Capture optional www and subdomain (better to list your subdomains inside (sub1|sub2|...) )
    RewriteRule .? http://%1com{%REQUEST_URI} [R=301,L]
    # Send {REQUEST_URI} to subdomain.com
    # Note, this can also send to www.maindomain.com 
    # (if you don't list as recommended above) but
    # that will be corrected below
    
    # 301 permanent redirect index.html(htm) to folder with exclusion for addon domains
    # Rephrased: Strip subdirectories from any index.htm(l) request
    # RewriteCond %{HTTP_HOST} !(addondomain\.com|addondomain\.com|addondomain\.com|addondomain\.com|addondomain\.com)
    # Irrelevant
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html?\ HTTP/
    # {THE_REQUEST} is a terrible variable to use and you don't need to use the whole thing!
    # In fact, you don't need to use it at all!
    RewriteRule .+/index\.html?$ http://www.maindomain.com/index.html [R=301,L]
    
    # 301 permanent redirect non-www (non-canonical) to www with exclusion for addon domains
    RewriteCond %{HTTP_HOST} !(addondomain\.com|addondomain\.com|addondomain\.com|addondomain\.com|websitecodetutorials\.com)
    # Ditto the above
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    RewriteRule .? http://www.maindomain.com${REQUEST_URI} [R=301,L]
    Don't forget to use the No Case flag when trying to match the {HTTP_HOST} variable.

    Questions? Problems?

    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
    SitePoint Wizard bronze trophy PicnicTutorials's Avatar
    Join Date
    Dec 2007
    Location
    Carlsbad, California, United States
    Posts
    3,658
    Mentioned
    15 Post(s)
    Tagged
    0 Thread(s)
    Thanks! so it should look like this? Am I missing anything?

    Code:
    RewriteEngine on
    
    # Send subdomains off to their own domains so 
    RewriteCond %{HTTP_HOST} ^((www\.)?([a-z]+\.))maindomain\.com$ [NC]
    RewriteRule .? http://%1com{%REQUEST_URI} [R=301,L]
    
    # 301 permanent redirect index.html(htm) to folder with exclusion for addon domains
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html?\ HTTP/
    RewriteRule .+/index\.html?$ http://www.maindomain.com/index.html [R=301,L]
    
    # 301 permanent redirect non-www (non-canonical) to www with exclusion for addon domains
    RewriteCond %{HTTP_HOST} !(addondomain\.com|addondomain\.com|addondomain\.com|addondomain\.com|addondomain\.com)
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    RewriteRule .? http://www.maindomain.com${REQUEST_URI} [R=301,L]

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

    Well, I was in a rush last time but was concerned about the optional www with a subdomain (which could also be www of the maindomain) but rushed your answer out to you anyway. My apologies for not taking sufficient time.

    Specificity:

    1. Enforce www on maindomain.

    2. Redirect all index.htm(l) to DocumentRoot's index.html


    Quote Originally Posted by EricWatson View Post
    Thanks! so it should look like this? Am I missing anything?

    Code:
    RewriteEngine on
    
    # Send subdomains off to their own domains then forget about them here
    RewriteCond %3 !^www\. [NC]
    RewriteCond %{HTTP_HOST} ^((www\.)?([a-z]+\.))maindomain\.com$ [NC]
    RewriteRule .? http://%1com{%REQUEST_URI} [R=301,L]
    
    # Enforce www
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    RewriteRule .? http://www.maindomain.com${REQUEST_URI} [R=301,L]
    
    # Redirect index.htm(l) to DocumentRoot's index.html
    RewriteRule .+/index\.html?$ index.html [R=301,L]
    Yes, taking the subdomains out of the equation with the first block meant that you no longer had to deal with them; enforcing www meant you no longer had to use an external redirection to the DocumentRoot's index.html file; and you didn't need to use {THE_REQUEST} for something that a RewriteRule can do far easily (which you were already doing anyway).

    Please note that only the last RewriteCond atoms can be used so the backreference to %3 was previously used to prevent the redirection from www.maindomain.com to www.com.

    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


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
  •