Autarchy of the Private Cave

Tiny bits of bioinformatics, [web-]programming etc

    • Archives

    • Recent comments

    My blog is now no-www Class B

    23rd March 2007

    Update: WordPress 2.5+ does not require adding rewrite rules to .htaccess, as it now redirects the browser to the correct (configured) URL itself. However, if you would like the redirection to be made by apache’s mod_rewrite rather than by PHP’s header() instruction (which I suspect to be slower than mod_rewrite), then you can still use the instructions below. (Another consideration to stick to mod_rewrite is the presence of other software installed into the root of the same domain as the WP blog; mod_rewrite solution works for all, while WP’s own redirect works only for WP.)

    See important update at the end of this post!

    In the early days of my acquaintance with internet, I considered it obligatory to add the “www.” part in front of every site (domain) name. As a matter of fact, without those three mysterious letters most of the websites “didn’t work”.

    Now, nearly a decade later, it appears clear to me that the www part is redundant. But it was only today, that I finally switched my blog to the use of Class B no-www policy. Earlier it was Class A, the most common.

    You can either go directly to no-www.org for full information, or read on for the short abstract.

    Please be advised, that no-www.org is able to check only the 2nd level domains like example.net; domains like bogdan.org.ua (third-level domain) cannot be checked (yet?). Of course, you can test the behaviour of your website when visited at either www. or no-www addresses to assign the class “manually” :).

    Class B:

    Class B means that all of the traffic to http://www.yourdomain.com is politely and silently redirected to http://yourdomain.com.

    Class B is currently the optimal no-www compliance level. This classification helps remind users that, while the www subdomain is accepted, it is not necessary. In Class B, www.example.net is a valid address, but it redirects all traffic to example.net.

    Class A:

    This is the most common no-www compliance level. With class A domains, example.net and www.example.net are both valid methods of reaching this website. Many servers default to this.

    Class C:

    Class C is the most stringent compliance level. According to no-www, www.example.net is an invalid subdomain. All traffic must go to example.net in order to view the site. Very few sites currently hold this classification, partially because many internet users are not yet savvy enough to drop the www every time. For that reason, this classification is not recommended for sites that serve the general public.

    To become Class B website, you need to create (if it didn’t exist) the .htaccess file in the document root of your site (this is usually the top-level folder which you can access from the browser, and it usually has files like robots.txt, favicon.ico, index.php, .htaccess :) ). Then add to your .htaccess file the following lines:

    1. <IfModule mod_rewrite.c>
    2. RewriteEngine On
    3. RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
    4. RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
    5. </IfModule>

    if you are running WordPress blog, the part of your .htaccess file may look similar to mine:

    1. # BEGIN WordPress
    2. <IfModule mod_rewrite.c>
    3. RewriteEngine On
    4. RewriteBase /
    5.  
    6. RewriteCond %{HTTP_HOST} ^www\.bogdan\.org\.ua$ [NC]
    7. RewriteRule ^(.*)$ http://bogdan.org.ua/$1 [R=301,L]
    8.  
    9. RewriteCond %{REQUEST_FILENAME} !-f
    10. RewriteCond %{REQUEST_FILENAME} !-d
    11. RewriteRule . /index.php [L]
    12. </IfModule>
    13. # END WordPress

    Note: if you are using Google Sitemaps, please do not forget to “Set preferred domain name” to the one without “www”, if you choose either Class B or Class C no-www compliance.

    Important update: it appears that either WordPress itself or one of the plugins I have installed occasionally rewrite the .htaccess file. More exactly, the portion of the file between the comments “# BEGIN WordPress” and “# END WordPress” is rewritten. Thus, any user-defined rules put into that section are lost. (I suspect this might be documented somewhere.)

    So the solution is to put the no-www mod_rewrite rules _above_ the WordPress portion of the file. Below is the example of how I did this:

    1. <IfModule mod_rewrite.c>
    2. RewriteEngine On
    3. RewriteBase /
    4. RewriteCond %{HTTP_HOST} ^www\.bogdan\.org\.ua$ [NC]
    5. RewriteRule ^(.*)$ http://bogdan.org.ua/$1 [R=301,L]
    6. </IfModule>
    7.  
    8. # BEGIN WordPress
    9. <IfModule mod_rewrite.c>
    10. RewriteEngine On
    11. RewriteBase /
    12. RewriteCond %{REQUEST_FILENAME} !-f
    13. RewriteCond %{REQUEST_FILENAME} !-d
    14. RewriteRule . /index.php [L]
    15. </IfModule>
    16. # END WordPress

    The only thing you have to keep in mind when adding no-www rewrite rules is that the WordPress portion is not under your control and should not be seen as “present” in the file, for the sake of reliability.

    Please update your .htaccess files, if you did the same mistake as I.

    Share

    3 Responses to “My blog is now no-www Class B”

    1. Will Says:

      Hi! Thanks for this post. I have been looking for a specific example. Does my code below look correct? I added the two middle lines to match your file. The other code was already in the file and also seems to match yours so it seems like it should be perfect? Thanks!

      # BEGIN WordPress

      RewriteEngine On
      RewriteBase /

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

      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.php [L]

      # END WordPress

    2. Bogdan Says:

      Looks correct to me. Should work.

    3. Kris Clouser Says:

      Thx for information.

    Leave a Reply

    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>