Welcome to WebmasterWorld Guest from 54.160.163.163

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Setting up 3 domains in one conf file

getting weird fluctuations

     

AnonyMouse

9:52 am on Jul 30, 2009 (gmt 0)

10+ Year Member



Hi,

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!

AnonyMouse

10:55 am on Jul 30, 2009 (gmt 0)

10+ Year Member



Hmm, as so often happens, posting in the forum led me to the right answer just because it made me think more logically about the problem!

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?)

jdMorgan

2:07 pm on Jul 30, 2009 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



We hope that most threads here are eventually [solved]... :)

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/

Also, in future, when using regular-expressions patterns as in your previous RewriteCond %{HTTP_HOST} directives, be sure to escape all literal periods and other characters which are interpreted as regex 'tokens':
 RewriteCond %{HTTP_HOST} ^exampl[b]e\.e[/b]s [NC]

Remember that in regular expressions, a period is taken as meaning "match any single character" and in some circumstances, failing to escape such characters can result in an exploitable vulnerability.

Jim

AnonyMouse

2:56 pm on Jul 30, 2009 (gmt 0)

10+ Year Member



Thanks Jim, I've made the suggested amendment - you're right, it's a much more succinct approach! And thanks for the tip on using "." in my regular expressions :-)
 

Featured Threads

Hot Threads This Week

Hot Threads This Month