Forcing non-WWW traffic to WWW on Apache without mod_rewrite

A tutorial on forcing non-WWW traffic to be redirected to WWW on Apache without the use of mod_rewrite.

Looking for a new simple way to plan your day? Get organized with Five.Today

If you have a domain like and you want to force your visitors to use, you can achieve this using various Apache configuration directives. Most of the examples I have seen online use mod_rewrite, but you can save yourself the complexity and overhead by using two virtual host directives instead.

Here is an example configuration from my /etc/httpd/conf/httpd.conf file (this is typically where the main configuration file is located on Redhat-based systems):

<VirtualHost *:80>
    Redirect permanent /
<VirtualHost *:80>
    <Directory /var/www/current>
        AllowOverride All
    DocumentRoot /var/www/current

The first virtual host entry captures all traffic to port 80 destined for the server named, and then re-directs this traffic to The second virtual host entry is the real entry that points to the directory where the source code resides. A simple but effective trick.

Looking for a modern PHP framework to build your new project? Please consider using the Alpha Framework

John Collins

I have been writing about web technology and software development since 2001. I am the developer of the Alpha Framework for PHP, and the Five.Today personal productivity app. I love open source, technology, and economics.