Redirect example.com to www.example.com

I just got Virtualmin GPL installed and can’t find where to do the following. I’d like all requests to http://example.com sent to the main site at http://www.example.com

Through my web searches I’ve seen many references to adding the following to a .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST}!^www.example.com.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

However, every time I do this I get an internal server error. So the question I’d like to ask is - is there a better way in Virtualmin to do what I’m trying to do besides create a .htaccess file? If not, why the (500) internal server errors?

I keep looking at “Aliases and Redirects” under Apache Webserver as the solution, but I’m not sure. Any help? Hopefully I’ve given enough detailed info. Thanks!

(PS: Please help before Googlebot shows up!)<br><br>Post edited by: rob944s2, at: 2008/02/28 10:31

Fixed the problem, but would still like to know if there’s a better way to do this using Virtualmin - let me know, thanks!

Here’s what I did. I kept getting internal server errors when accessing the folder with htaccess because RewriteEngine was not enabled. To enable it choose Webmin > Servers > Apache Webserver > Global Configuration > Configure Apache Modules | Then click the box next to “rewrite” and click the “Enable Selected Modules” button at the bottom. I also clicked “Apply Changes” on the main Apache page.

Here’s the actual code I used in my .htaccess:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.example.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]

Again, if there’s a better way to do this in Virtualmin let me know. On Plesk it’s just a simple checkbox - so I know that there must be a better way in Virtualmin.

Fixed the problem, but would still like to know if there’s a better way to do this using Virtualmin - let me know, thanks!

Here’s what I did. I kept getting internal server errors when accessing the folder with htaccess because RewriteEngine was not enabled. To enable it choose Webmin > Servers > Apache Webserver > Global Configuration > Configure Apache Modules | Then click the box next to “rewrite” and click the “Enable Selected Modules” button at the bottom. I also clicked “Apply Changes” on the main Apache page.

Here’s the actual code I used in my .htaccess:

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.example.com
RewriteRule ^(.*)$ http://www.example.com/$1 [R=permanent,L]

Again, if there’s a better way to do this in Virtualmin let me know. On Plesk it’s just a simple checkbox - so I know that there must be a better way in Virtualmin.

You could add those to the Server Templates website configuration. There is a field for additional directives (and you can use ${DOM} to get the domain name within the templates and www.${DOM} to get the fully qualified name you’re wanting to rewrite to).