.htaccess problems

Hi everyone,

I’m trying to use .htaccess to do two things:

  1. If the user goes to the non-www version of my site add the www, e.g. http://domain.com/, http://domain.com/page/ etc redirect to http://www.domain.com/, http://www.domain.com/page/ etc

  2. After checking for this, if the user hasn’t input the trailing slash on an address, add it, e.g. http://www.domain.com becomes http://www.domain.com/ and http://www.domain.com/page becomes http://www.domain.com/page/

I’ve modified my .htaccess file so it now reads as follows, but:

  1. the trailing slashes aren’t being added at all

  2. the redirect is only working from http://domain.com/ to http://www.domain.com - http://domain.com/page takes me to http://www.domain.com/index.php

Any ideas where I’m going wrong? I really don’t understand .htaccess, this code was cobbled together from the Net


---- .htaccess file ----

BEGIN WordPress

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

END WordPress

If requested resource does not exist as a file

RewriteCond %{REQUEST_FILENAME} !-f

and does not end with a period followed by a filetype

RewriteCond %{REQUEST_URI} !..+$

and does not end with a slash

RewriteCond %{REQUEST_URI} !/$

then add a trailing slash and redirect

RewriteRule (.*) $1/ [R=301,L]

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^guyrintoul.com [nc]
rewriterule ^(.*)$ http://www.guyrintoul.com/$1 [r=301,nc]