0

How can I make it so that whenever a page on mydomain.com is accessed without www to go to www.mydomain.com, please?

Thank you.

Francisc
  • 143
  • 1
  • 3
  • 11
  • I think this answers your question: http://serverfault.com/questions/120488/redirect-url-within-apache-virtualhost – cstamas Apr 10 '11 at 22:08

1 Answers1

2

Try this in your .htaccess file:

Options +FollowSymLinks
RewriteEngine on

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

# redirect for https
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]  
RewriteCond %{SERVER_PORT} =443
RewriteRule ^/?(.*)$ https://www.mydomain.com/$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

anubhava
  • 411
  • 4
  • 8