views:

15

answers:

1

Hi! To rewrite example.com to www.example.com I was told to use the following rules within my root .htaccess file:

# Require the www
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/robots\.txt$
RewriteCond %{REQUEST_URI} !^/sitemap\.xml$
RewriteCond %{REQUEST_URI} !^/favicon\.ico$
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

Could you please explain what's the matter with the first five lines here? Are they really needed/recommended? TIA

+1  A: 

.htaccess tricks This article will help you to understand all the tricks about htaccess . Later yourself decide whether you need first five lines

Hope its helpful

YetAnotherCoder
Thanks for the link! I just noticed the 301 redirection does not work if I use RewriteCond %{REQUEST_FILENAME} !-f and RewriteCond %{REQUEST_FILENAME} !-d. Adding [OR] behind the first condition fixes this. Can you please explain why?
lupee