Forbid or redirect depending on hostname

Forbid or redirect depending on hostname

Post by Warren Bel » Sat, 07 Apr 2001 05:11:07



I'm running Apache with my own domain name.  I'm also running a mail
server.  what I want to do is create a CNAME for my domain so my mail
server can be accessed with mail.mydomain.com.  But I don't want someone
to be able to type int http://mail.mydomain.com/ and get the website.
What can I use in my Apache configs to return a forbidden message if
they try to access http://mail.mydomain.com?  Or even better, is there a
way to redirect anyone trying to access http://mail.mydomain.com to
http://www.mydomain.com and have it change the URL in their browser when
it does the redirect?

TIA

 
 
 

Forbid or redirect depending on hostname

Post by adam » Sat, 07 Apr 2001 05:25:27



> I'm running Apache with my own domain name.  I'm also running a mail
> server.  what I want to do is create a CNAME for my domain so my mail
> server can be accessed with mail.mydomain.com.  But I don't want someone
> to be able to type int http://www.veryComputer.com/
> What can I use in my Apache configs to return a forbidden message if
> they try to access http://www.veryComputer.com/?  Or even better, is there a
> way to redirect anyone trying to access http://www.veryComputer.com/ to
> http://www.veryComputer.com/ and have it change the URL in their browser when
> it does the redirect?

You'll need mod_rewrite:

Rewri*gine On
RewriteCond %{HTTP_HOST} mail\.mydomain\.com
RewriteRule ^(.*)$ http://www.veryComputer.com/$1 [R]

--
-adam                 | "Be liberal in what you accept, and
Systems Administrator |  conservative in what you send"
Indiana University    |      -Jon Postel
Bloomington, Indiana  |

 
 
 

Forbid or redirect depending on hostname

Post by Warren Bel » Sat, 07 Apr 2001 05:56:00




> > I'm running Apache with my own domain name.  I'm also running a mail
> > server.  what I want to do is create a CNAME for my domain so my mail
> > server can be accessed with mail.mydomain.com.  But I don't want someone
> > to be able to type int http://www.veryComputer.com/
> > What can I use in my Apache configs to return a forbidden message if
> > they try to access http://www.veryComputer.com/?  Or even better, is there a
> > way to redirect anyone trying to access http://www.veryComputer.com/ to
> > http://www.veryComputer.com/ and have it change the URL in their browser when
> > it does the redirect?

> You'll need mod_rewrite:

> Rewri*gine On
> RewriteCond %{HTTP_HOST} mail\.mydomain\.com
> RewriteRule ^(.*)$ http://www.veryComputer.com/$1 [R]

> --
> -adam                 | "Be liberal in what you accept, and
> Systems Administrator |  conservative in what you send"
> Indiana University    |      -Jon Postel
> Bloomington, Indiana  |

Does this need to be inside the <Directory> markers or anywhere in the
httpd.conf?  I run virtual hosts but my main site is the one I'm using
this on and it uses the main http.conf.

I put in what you posted, changed it to my domain and made sure I was
using mod_rewrite but it's not working.  If I go to mail.mydomain.com it
brings up the website and the address in the browser stays at
mail.mydomain.com.  Any ideas on what could be wrong?

 
 
 

Forbid or redirect depending on hostname

Post by adam » Sat, 07 Apr 2001 06:03:11



> Does this need to be inside the <Directory> markers or anywhere in the
> httpd.conf?  I run virtual hosts but my main site is the one I'm using
> this on and it uses the main http.conf.

Should be ok anywhere.  If you want to debug, you can use
RewriteLogLevel 5, RewriteLog <someplace>.

Quote:> I put in what you posted, changed it to my domain and made sure I was
> using mod_rewrite but it's not working.  If I go to mail.mydomain.com it
> brings up the website and the address in the browser stays at
> mail.mydomain.com.  Any ideas on what could be wrong?

You didn't say you restarted the server, but I'll assume you did.  If
you've already got namebased virtualhosts you might try:

<VirtualHost mail.mydomain.com>
Redirect / http://www.mydomain.com/
</VirtualHost>

Could also be a browser cache issue, you might make sure to clear caches
and restart the browser.  Also, you could use telnet or lynx to check
the http headers:

lynx -dump -head http://mail.mydomain.com/

telnet mail.mydomain.com 80
GET / HTTP/1.1
Host: mail.mydomain.com
Connection: Close

<hit enter twice after that last line>

--
-adam                 | "Be liberal in what you accept, and
Systems Administrator |  conservative in what you send"
Indiana University    |      -Jon Postel
Bloomington, Indiana  |

 
 
 

Forbid or redirect depending on hostname

Post by Warren Bel » Sat, 07 Apr 2001 06:30:12




> > Does this need to be inside the <Directory> markers or anywhere in the
> > httpd.conf?  I run virtual hosts but my main site is the one I'm using
> > this on and it uses the main http.conf.

> Should be ok anywhere.  If you want to debug, you can use
> RewriteLogLevel 5, RewriteLog <someplace>.

I tried this, replaced <someplace> with /etc/httpd/rewrite.log and
restarted the server and get this error:

Starting httpd: Syntax error on line 792 of /etc/httpd/conf/httpd.conf:
RewriteLogLevel takes one argument, the level of the rewriting logfile
verbosity (0=none, 1=std, .., 9=max)
[FAILED]

Quote:

> > I put in what you posted, changed it to my domain and made sure I was
> > using mod_rewrite but it's not working.  If I go to mail.mydomain.com it
> > brings up the website and the address in the browser stays at
> > mail.mydomain.com.  Any ideas on what could be wrong?

> You didn't say you restarted the server, but I'll assume you did.  If
> you've already got namebased virtualhosts you might try:

> <VirtualHost mail.mydomain.com>
> Redirect / http://www.mydomain.com/
> </VirtualHost>

When I do this and access any page by mail.mydomain.com it redirects me
to www.mydomain.com but gives me a 302 Found page with a link saying
document can be found here.  When you click the link it brings you to
the same Found page.  So basically it doesn't go anywhere.

Quote:> Could also be a browser cache issue, you might make sure to clear caches
> and restart the browser.  Also, you could use telnet or lynx to check
> the http headers:

> lynx -dump -head http://mail.mydomain.com/

> telnet mail.mydomain.com 80
> GET / HTTP/1.1
> Host: mail.mydomain.com
> Connection: Close

> <hit enter twice after that last line>

This returns:

lynx -dump -head http://mail.mydomain.com/
HTTP/1.1 200 OK
Date: Thu, 05 Apr 2001 21:13:27 GMT
Server: Apache-AdvancedExtranetServer/1.3.14 (Linux-Mandrake/2mdk)
Connection: close
Content-Type: text/html

Any ideas?

 
 
 

Forbid or redirect depending on hostname

Post by adam » Sat, 07 Apr 2001 06:46:23



> > Should be ok anywhere.  If you want to debug, you can use
> > RewriteLogLevel 5, RewriteLog <someplace>.

> I tried this, replaced <someplace> with /etc/httpd/rewrite.log and
> restarted the server and get this error:

Sorry, I thought you'd get that those were two different commands:
RewriteLogLevel 5
RewriteLog <someplace>

Quote:> > > I put in what you posted, changed it to my domain and made sure I was
> > > using mod_rewrite but it's not working.  If I go to mail.mydomain.com it
> > > brings up the website and the address in the browser stays at
> > > mail.mydomain.com.  Any ideas on what could be wrong?

> > You didn't say you restarted the server, but I'll assume you did.  If
> > you've already got namebased virtualhosts you might try:

> > <VirtualHost mail.mydomain.com>
> > Redirect / http://www.mydomain.com/
> > </VirtualHost>

> When I do this and access any page by mail.mydomain.com it redirects me
> to www.mydomain.com but gives me a 302 Found page with a link saying
> document can be found here.  When you click the link it brings you to
> the same Found page.  So basically it doesn't go anywhere.

Maybe you should include more of your httpd.conf, you are running
named-based virtual hosts right?  

You might actually want:

<VirtualHost my.ip.address.here>
ServerName mail.mydomain.com
Redirect / http://www.mydomain.com/
</VirtualHost>

Take out the Rewrite* if you add this.

-adam                 | "Be liberal in what you accept, and
Systems Administrator |  conservative in what you send"
Indiana University    |      -Jon Postel
Bloomington, Indiana  |

 
 
 

Forbid or redirect depending on hostname

Post by Warren Bel » Sat, 07 Apr 2001 07:00:10




> > > Should be ok anywhere.  If you want to debug, you can use
> > > RewriteLogLevel 5, RewriteLog <someplace>.

> > I tried this, replaced <someplace> with /etc/httpd/rewrite.log and
> > restarted the server and get this error:

> Sorry, I thought you'd get that those were two different commands:
> RewriteLogLevel 5
> RewriteLog <someplace>

> > > > I put in what you posted, changed it to my domain and made sure I was
> > > > using mod_rewrite but it's not working.  If I go to mail.mydomain.com it
> > > > brings up the website and the address in the browser stays at
> > > > mail.mydomain.com.  Any ideas on what could be wrong?

> > > You didn't say you restarted the server, but I'll assume you did.  If
> > > you've already got namebased virtualhosts you might try:

> > > <VirtualHost mail.mydomain.com>
> > > Redirect / http://www.mydomain.com/
> > > </VirtualHost>

> > When I do this and access any page by mail.mydomain.com it redirects me
> > to www.mydomain.com but gives me a 302 Found page with a link saying
> > document can be found here.  When you click the link it brings you to
> > the same Found page.  So basically it doesn't go anywhere.

> Maybe you should include more of your httpd.conf, you are running
> named-based virtual hosts right?

> You might actually want:

> <VirtualHost my.ip.address.here>
> ServerName mail.mydomain.com
> Redirect / http://www.mydomain.com/
> </VirtualHost>

Ok this works.  I'm using name based virtual hosts like:

<VirtualHost *>
ServerName mail.mydomain.com
Redirect / http://www.mydomain.com/
</VirtualHost>

Now, is it because I'm using virtual hosts that mod_rewrite didn't
work?  Which one's better, it seems like the virtualhost is sort of a
hack?  What could be causing rewrite not to work?

Thanks for the help.

- Show quoted text -

Quote:> Take out the Rewrite* if you add this.

> -adam                 | "Be liberal in what you accept, and
> Systems Administrator |  conservative in what you send"
> Indiana University    |      -Jon Postel
> Bloomington, Indiana  |

 
 
 

1. Redirect, depending on User-Agent (?)

In Apache, how can I specify Redirect only for certain browsers ? In fact, I
just want MSIE 3.0 to be redirected to another virtual server. If this is at
all possible, I will be VERY thankful for any help.

Best wishes to all Apache administrators,

Alexander N. Andreyev, In His Own Mind

Personal Web Page:  http://greenland.srcc.msu.su
Parallel Computing: http://parallel.srcc.msu.su (Russian language)

P.S. I repeat my previous question (may be, it didn't get through). Is is
possible to make SSI module parse the HTML output of my CGI script
(specified by Action text/html ... ) ?

2. Trying to bootup from SLS 1.03 a1 : LIL-

3. Need Help with Apache: Redirect depending on clients IP-Adress

4. benchmark support SOCKS 5 ??

5. Mesa depends on XFree86, but XFree86 depends on Mesa!

6. Log file problem

7. redirecting to different hostname and dropping query string

8. SIGHUP sending when modem drops CD

9. Redirects based on remote hostname?

10. hostname redirect

11. Better way to do Apache hostname redirects than this?

12. howto? hostname.domain redirect to http://someplace.blabla

13. how to redirect on hostname?