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 can I make it so that whenever a page on is accessed without www to go to, please?

Thank you.

share|improve this question
I think this answers your question:… – cstamas Apr 10 '11 at 22:08
up vote 1 down vote accepted

Try this in your .htaccess file:

Options +FollowSymLinks
RewriteEngine on

# redirect for http
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]  
RewriteCond %{SERVER_PORT} =80
RewriteRule ^/?(.*)$$1 [R=301,QSA,L,NE]

# redirect for https
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]  
RewriteCond %{SERVER_PORT} =443
RewriteRule ^/?(.*)$$1 [R=301,QSA,L,NE]

R=301 will redirect with https status 301
L will make last rule
NE is for no escaping query string
QSA will append your existing query parameters

$1 is your REQUEST_URI

share|improve this answer
Your ^(.*)$ will capture the leading slash; you don't want to add a second in the location that you're redirecting to. – Shane Madden Apr 10 '11 at 22:29
@Shane Madden: Thanks I fixed it. – anubhava Apr 10 '11 at 23:20
I don't need the FollowSymLinks do I? – Francisc Apr 11 '11 at 11:31
It's not 100% good yet. :) If I enter: it will go to instead of – Francisc Apr 11 '11 at 11:36
@Francisc: Please see my edited answer, that takes care of http and https both. – anubhava Apr 11 '11 at 12:19

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.