0

I am kinda new in apache config.

I wish to redirect my traffic from http://example.com to http://www.example.com

I want www always appear in my visitor's browser's address bar.

Should i use mod_rewrite or anything else in httpd.conf?

Konerak
  • 39,272
  • 12
  • 98
  • 118
Bill Kary
  • 685
  • 2
  • 12
  • 27
  • possible duplicate of [apache redirect from non www to www](http://stackoverflow.com/questions/1100343/apache-redirect-from-non-www-to-www) – Konerak Mar 14 '11 at 10:01
  • Sorry, there are already tons of questions on this site about redirecting www to nothing or nothing to www using apache. Use the search-function for a bit? – Konerak Mar 14 '11 at 10:02

1 Answers1

2

Add the following to your httpd.conf

<VirtualHost *:80>
        ServerName adomainwihtoutwww.com
        Redirect permanent / http://www.yourdomain.com/
    </VirtualHost>
Bill Kary
  • 685
  • 2
  • 12
  • 27
  • `Redirect permanent` is not recommended if you want to add subdomains later. A user who used that subdomain before it was registred as virtual host may never reach that page since there is `301 Moved Permanently` in its browser's cache. – Martin Schneider Feb 01 '17 at 18:25