Forum Moderators: phranque
After much frustration, I finally go my rewrite rule working in the httpd.conf file.
Here is the code:
<VirtualHost 99.99.99.999>
DocumentRoot "/var/www/html/site.com"
ServerName www.site.com
ServerAlias site.com
CustomLog logs/www.site.com-access_log combined
# Begin Rewrite Code
Options +FollowSymLinks
RewriteEngine on
# if hostname is not blank
RewriteCond %{HTTP_HOST} .
# and if hostname does not start with "www."
RewriteCond %{HTTP_HOST}!^www\.
# prepend "www." to hostname and redirect
RewriteRule ^/(.*)$ [%{HTTP_HOST}...] [R=301,L]
<Directory "/var/www/html/site.com">
allow from all
Options -Indexes
</Directory>
</VirtualHost>
The reason it wasn't working before was I had it outside of the Virtual Host tags I guess.
Anyway, it's working now, but I want it to apply to EVERY site on the server instead of just the site which it resides in the VirtualHost tags.
Where should I put the rewrite code so it works for ALL virtual hosts on the server?
Thanks,
Dan