I want to 301 redirect all example.org to www.example.org. The following example is doing just that, but it's got a lot of noise to it and is thus hard to maintain and error prone:
<VirtualHost 192.0.2.123:80>
ServerName example.org
RedirectPermanent / http://www.example.org
</VirtualHost>
<VirtualHost 192.0.2.123:80>
ServerName www.example.org
DocumentRoot /usr/local/www/example
</VirtualHost>
Do you happen to know if there's some shorter version for the whole thing above?
Something like this pseudo-config:
<VirtualHost 192.0.2.123:80>
ServerName www.example.org
ServerAlias example.org
# Redirect-Every-ServerAlias-To-ServerName
DocumentRoot /usr/local/www/example
</VirtualHost>
So that way I would just need to provide every subdomain that should be redirected under ServerAlias
?
Use mod_rewrite, something like this:
make sure to put them in the right order, www first