Forum Moderators: phranque
I'm running a dedicated server, and have access to the httpd.conf files.
I currently have two domains running on there, call it example.com and example.es - the latter simply redirects to example.com
What's weird is that the redirect for example.es sometimes works, and sometimes doesn't - it instead points to the DocRoot.
Here is the conf file:
NameVirtualHost 192.168.10.7:80
<VirtualHost 192.168.10.7:80>
ServerName www.example.com
ServerAlias example.com
ServerAdmin webmaster@example.com
<Directory "/home/htdocs">
AllowOverride All
Options FollowSymLinks
Order allow,deny
Allow from all
</Directory>
DocumentRoot "/home/htdocs"
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*) http://www.example.com [R=301]
# 301 redirect other domains over to .com
RewriteCond %{HTTP_HOST} ^example.es [NC]
RewriteCond %{REQUEST_URI} ^/
RewriteRule ^ http://www.example.com/ [L,R=301]
</VirtualHost>
Have I set this up correctly? I want to add a couple more domains that just do a 301 redirect to the example.com, and am concerned that even my first redirect is not functioning as expected :-(
A second question: I want to add another domain, running a separate site.
I tried adding a seperate VirtualHost like this:
<VirtualHost 192.168.10.7:80>
ServerName www.example2.com
ServerAlias example2.com
ServerAdmin webmaster@example2.com
<Directory "/home/htdocs2">
AllowOverride All
Options FollowSymLinks
Order allow,deny
Allow from all
</Directory>
DocumentRoot "/home/htdocs2"
</VirtualHost>
But strangely, all that does is also point to the DocRoot of the FIRST virtual host (i.e. /home/htdocs instead of /home/htdocs2).
I'm a little out of my depth here, and would really appreciate any feedback on what I'm doing wrong. Many thanks!
The issue with the fluctuating redirect was that the rule I had above was only redirecting the non-www url...ahem
It also turned out to be more logical to add a virtual host just for that redirect, like so:
# ============ Redirecting example.es =============
<VirtualHost 192.168.10.7:80>
ServerName www.example.es
ServerAlias example.es
ServerAdmin webmaster@example.es
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
</VirtualHost>
#==================================================
So all good! (Mods, how can I add [SOLVED] to the subject line?)
However, that doesn't always mean there's nothing left to discuss.
Note that you could use a single mod_alias directive instead of the far-more-complex mod_rewrite for this purpose:
Redirect 301 / http://www.example.com/
RewriteCond %{HTTP_HOST} ^exampl[b]e\.e[/b]s [NC]
Jim