.htaccess in wordpress site issue

Google’s WMT tools is seeing my site as 2 different sites so I want to implement a 301 redirect from non www to www. The main site www.mysite.com is built using Flash and a folder that contains the wordpress blog is held seperatly in www.mysite.com/blog/.

In the WordPress folder there is a .htaccess file with the following script which doesn’t look right as there are 2 RewriteRules and RewriteCond entries. Should I remove 1 of them or are they both needed?

Read More

Why is !-f and !-d in there – what do they do?

Also should my main Flash site have its own .htaccess file for the 301 non-www to www?

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

Related posts

Leave a Reply

1 comment

  1. <IfModule mod_rewrite.c>
    
    RewriteEngine On
    RewriteBase /blog/
    
    #If the file requested is index.php from the current folder(here: blog)
    #do not do anything
    RewriteRule ^index.php$ - [L]
    
    #if other requests are not regular files or directories,
    #redirect it to /blog/index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /blog/index.php [L]
    
    </IfModule>
    

    Do not remove any of the above rules. They are fine & required. In fact, I would suggest you to add this as well:

    RewriteCond %{REQUEST_FILENAME} !-l
    

    From rewritecond apache docs :
    -f, -d & -l are variants of CondPatterns. Instead of real regular expression strings.

    • ‘-d’ (is directory)
      Treats the TestString as a pathname and tests whether or not it exists, and is a directory.
    • ‘-f’ (is regular file)
      Treats the TestString as a pathname and tests whether or not it exists, and is a regular file.
    • ‘-l’ (is symbolic link)
      Treats the TestString as a pathname and tests whether or not it exists, and is a symbolic link.

    if prefixed by an exclamation mark (‘!’) it leads to negate their meaning. i.e. !-f means is not a regular file.


    For redirecting from non www to www urls use this in your .htaccess in your DocumentRoot:

    RewriteEngine on
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} !^www. [NC]
    RewriteRule ^(.*)$ www.mysite.com/$1 [L,R=301]