0

This is linked to Rewriting subdomain.domain.com when other 'subdomains' exist

I need mod_rewrite to 'stop' processing, but it seems to continue on.

On my registrar, I've set A records as:

* 12.34.56.78 
@ 12.34.56.78
mgr 12.34.56.79  [it was working, and is working]
dbaccess 12.34.56.79    [this is something new I added]

My httpd.conf looks like this now:

<VirtualHost 12.34.56.79:80>    // notice the 79 which is something I'm trying out!
ServerAlias dbaccess.example.com
DocumentRoot /var/www/html/dbaccess
ServerName dbaccess.example.com
</VirtualHost>

NameVirtualHost 12.34.56.78:80

<VirtualHost 12.34.56.78:80>
ServerAlias *.example.com   // trying to catch science.example.com
DocumentRoot /var/www/html/site
ServerName www.example.com

 <IfModule mod_rewrite.c>
    RewriteEngine On
    ...
    RewriteCond %{HTTP_HOST} ^science\.example\.com [NC]
    RewriteRule (.*) http://www.example.com/classes/science/280.html [R=301,L]

    RewriteCond %{HTTP_HOST} !^www\.
    RewriteCond %{HTTPS}s ^on(s)|
    RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    ...
</VirtualHost>

// this is needed for other purposes
Listen *:2194

<VirtualHost *:2194>
   Redirect / http://mgr.example.com/
</VirtualHost>

Here is what works and what doesn't:

http://www.example.com/ works fine
http://mgr.example.com/ works fine
http://science.example.com/ works fine
http://dbaccess.example.com/ does NOT work fine

Accessing dbaccess.example.com redirects me to www.dbaccess.example.com (the same if I do doesnotexist.example.com which gets redirected to www.doesnotexist.example.com )

How do I get dbaccess.example.com to show contents of /var/www/html/dbaccess ?

siliconpi
  • 1,807
  • 6
  • 32
  • 46
  • Have you verified that the DNS entries are working as intended, via a ping or host lookup like `dig` or `nslookup`? – Tim Dec 29 '11 at 16:32
  • Does that machine / server also have two network interfaces or two ip addresses? – Tim Dec 29 '11 at 16:34
  • 1
    You don't have a `` for the `mgr` name on .79; where's it served from? Seems like you might just need a `NameVirtualHost 12.34.56.79:80`, but it seems like there's pieces of the config missing.. – Shane Madden Dec 29 '11 at 16:55
  • Hi Tim - the machine does have two ip addresses (its a hosted server). nslookup dbaccess.example.com shows: Server: resolver1.opendns.com Address: 208.67.222.222 Non-authoritative answer: Name: dbaccess.example.com Address: 12.34.56.79 – siliconpi Dec 29 '11 at 16:58
  • Hi Shane - I think it just goes to the default port 80 page. If I access 12.34.56.79 (the IP address), it goes to that mgr page itself. – siliconpi Dec 29 '11 at 17:11

2 Answers2

0

Change:

NameVirtualHost 12.34.56.78:80

to

NameVirtualHost *:80

to ensure that the vhosts receives requests on both IP interfaces

Mathias R. Jessen
  • 25,161
  • 4
  • 63
  • 95
  • I tried that - it gave a warning: [Fri Dec 30 03:44:52 2011] [warn] NameVirtualHost *:80 has no VirtualHosts – siliconpi Dec 30 '11 at 03:47
  • Try declaring both then: `NameVirtualHost 12.34.56.78:80` and `NameVirtualHost 12.34.56.79:80` each on a new line – Mathias R. Jessen Dec 30 '11 at 04:05
  • Hmm - now I'm back to the issue that accessing dbaccess.example.com shows me mgr.example.com – siliconpi Dec 30 '11 at 07:48
  • Like Shane above, I'm a little confused about the "mgr.example.com" site. Is it configured in apache? cause then you seem to have left out some of the configuration. When you go to dbaccess.example.com, what happens? Do you get redirected? Or does dbaccess.example.com present the content that you would expect from mgr.example.com? – Mathias R. Jessen Dec 30 '11 at 14:37
  • Sorry about that - you're absolutely right that that is a 'missing part' of the puzzle. We apparently have an application running Tomcat on our server that is listening / serving on that port and ip. – siliconpi Dec 31 '11 at 09:42
0

I needed to configure things differently, it was getting way more complicated than necessary.

I have the following as my A records:

* 12.34.56.78 
@ 12.34.56.78
mgr 12.34.56.79

I removed:
dbaccess 12.34.56.79

My httpd.conf now reads:

// back to original
NameVirtualHost 12.34.56.78:80

<VirtualHost 12.34.56.78:80>
ServerAlias www.example.com science.example.com // change made that works
DocumentRoot /var/www/html/site
ServerName www.example.com

<IfModule mod_rewrite.c>
    RewriteEngine On
    ...
    RewriteCond %{HTTP_HOST} ^science\.example\.com [NC]
    RewriteRule (.*) http://www.example.com/classes/science/280.html [R=301,L]

    RewriteCond %{HTTP_HOST} !^www\.
    RewriteCond %{HTTPS}s ^on(s)|
    RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    ...
</VirtualHost>

// back to original
<VirtualHost 12.34.56.78:80>
ServerAlias dbaccess.example.com
DocumentRoot /var/www/html/dbaccess
ServerName dbaccess.example.com
</VirtualHost>

Listen *:2194

<VirtualHost *:2194>
   Redirect / http://mgr.example.com/
</VirtualHost>
siliconpi
  • 1,807
  • 6
  • 32
  • 46