• Hi guys, i wish to add to the current .htaccess file that resides in my blog root so that if a user types in http://domain.com they’re automatically redirected to http://www.domain.com.

    I have opened up the current .htaccess file and I found the following:
    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /blog/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blog/index.php [L]
    </IfModule>

    # END WordPress

    To enforce the www i added the following to the .htaccess file:
    Options +FollowSymLinks
    RewriteEngine On
    RewriteCond %{HTTP_Host} ^cormacmoylan.com/blog [NC]
    RewriteRule ^(.*)$ http://www.cormacmoylan.com/blog/$1 [L,R=301]

    But it doesn’t enforce the rule. Does anyone know where i’m going wrong?

Viewing 2 replies - 1 through 2 (of 2 total)
  • To make your life much easier, although maybe less satisfying, there’s a plugin that will do this for you at

    http://txfx.net/code/wordpress/enforce-www-preference/

    Moderator Samuel Wood (Otto)

    (@otto42)

    WordPress.org Admin

    The .htaccess way is better, IMO.

    Few things:
    -“HTTP_Host” should be all caps. HTTP_HOST is the correct way. This is probably why it’s not working, caps matters.
    -The convention for RewriteRules is to have the L last. So use “[R=301,L]” instead. Not sure if this matters or not, but still.
    – Your rules should be BEFORE the #BEGIN WordPress line if you want them to work.

    I use the same sort of thing, actually. Only I enforce no www in my URL. See http://no-www.org . 🙂

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘.htaccess modification’ is closed to new replies.