Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How to redirect everything from no-www to www except for few files, using .htaccess?

I am using the following .htaccess to redirect no-www to www.


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

How do I add exception for few files?
for example:
1) should not be redirected to
2) should not be redirected to

Everything other then and should be redirected to

share|improve this question
up vote 2 down vote accepted

You could chain your RewriteCond directives, e.g.:

RewriteEngine on
RewriteCond %{REQUEST_URI} ! ^/page1\.html$
RewriteCond %{REQUEST_URI} ! ^/xml/page2\.xml$
RewriteCond %{http_host} ^[^.]+\.[^.]+$ [nc]
RewriteRule ^(.*)$ http://www.%{http_host}/$1 [r=301,nc]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.