You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Scott Wilcox <sc...@x0f.org> on 2007/05/18 12:58:45 UTC

[users@httpd] Global Vhost/Redirect

hey folks.

I have various virtual hosts set up on apache, and currently, the first
<VirtualHost> handles all unreferenced domains. I'm looking at
implementing something to catch any unreferenced domains and actually
shoot a rewrite at them to point them to my actual main URI.

Is this possible, and what would be the best/most efficient way to do it?

Thanks in advance,

Scott.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Global Vhost/Redirect

Posted by Scott Wilcox <sc...@x0f.org>.
Ha, nevermind. Again, i'm a retard.

All I needed to do was add a condition to the rewrite.

Thanks again Joshua.

Scott.

Scott Wilcox wrote:
> I took the mod_rewrite approach, and it works flawlessly. One question
> I have, is that I often access the server via its IP instead of the
> canonical name. Is there a way to make apache use both domain.tld and
> its IP as the server name?
>
> I've tried it with ServerAlias and it didn't make any difference, the
> only way I see of doing this would be duplicating the VirtualHost
> thats doing the redirecting and using the IP of the box as the server
> name.
>
> I'm pretty sure thats not a good idea though :p
>
> Scott.

Re: [users@httpd] Global Vhost/Redirect

Posted by Joshua Slive <jo...@slive.ca>.
On 5/18/07, Scott Wilcox <sc...@x0f.org> wrote:
>
>  I took the mod_rewrite approach, and it works flawlessly. One question I
> have, is that I often access the server via its IP instead of the canonical
> name. Is there a way to make apache use both domain.tld and its IP as the
> server name?
>
>  I've tried it with ServerAlias and it didn't make any difference, the only
> way I see of doing this would be duplicating the VirtualHost thats doing the
> redirecting and using the IP of the box as the server name.

I don't understand the question on several levels. Do you or don't you
want a request for http://your.ip.address/ redirected to
http://your.canonical.name/? If so, then it should happen
automatically with that recipe. If not, then you need to add a
specific RewriteCond excluding the ip address from being redirected.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Global Vhost/Redirect

Posted by Scott Wilcox <sc...@x0f.org>.
I took the mod_rewrite approach, and it works flawlessly. One question I
have, is that I often access the server via its IP instead of the
canonical name. Is there a way to make apache use both domain.tld and
its IP as the server name?

I've tried it with ServerAlias and it didn't make any difference, the
only way I see of doing this would be duplicating the VirtualHost thats
doing the redirecting and using the IP of the box as the server name.

I'm pretty sure thats not a good idea though :p

Scott.

Scott Wilcox wrote:
> AH. I'm a retard.
>
> Thanks Joshua :)
>
> Joshua Slive wrote:
>> On 5/18/07, Scott Wilcox <sc...@x0f.org> wrote:
>>>
>>>  Hey Joshua,
>>>
>>>  I think I was a little ambiguous with what I said. It probably
>>> would of
>>> been better to explain it like this.
>>>
>>>  If a VirtualHost is there for the requested URI, that is served.
>>>  For any requested URI (http://test1.com, http://sub.domain.com,
>>> http://anything.anythingelse.anywhere.tld), then that
>>> request is actually forwarded to the main site.
>>>
>>>  At the moment, my first VirtualHost is catching everything and
>>> displaying
>>> the standard homepage fine, but i'd much prefer if they were pushed
>>> over to
>>> the correct URI.
>>
>> Did you read the link I sent? That is exactly what it does.
>>
>> As it says, the first <VirtualHost> is the default host which catches
>> all names that don't match any other virtualhost. Put a Redirect in
>> that host pointing to your "canonical" vhost (the "correct URI"),
>> which should be contained in a separate <VirtualHost> section.
>>
>> Joshua.
>>
>> ---------------------------------------------------------------------
>> The official User-To-User support forum of the Apache HTTP Server
>> Project.
>> See <URL:http://httpd.apache.org/userslist.html> for more info.
>> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
>> For additional commands, e-mail: users-help@httpd.apache.org
>>
>>
> ------------------------------------------------------------------------
>
> No virus found in this incoming message.
> Checked by AVG Free Edition. 
> Version: 7.5.467 / Virus Database: 269.7.3/809 - Release Date: 17/05/2007 17:18
>   

Re: [users@httpd] Global Vhost/Redirect

Posted by Scott Wilcox <sc...@x0f.org>.
AH. I'm a retard.

Thanks Joshua :)

Joshua Slive wrote:
> On 5/18/07, Scott Wilcox <sc...@x0f.org> wrote:
>>
>>  Hey Joshua,
>>
>>  I think I was a little ambiguous with what I said. It probably would of
>> been better to explain it like this.
>>
>>  If a VirtualHost is there for the requested URI, that is served.
>>  For any requested URI (http://test1.com, http://sub.domain.com,
>> http://anything.anythingelse.anywhere.tld), then that
>> request is actually forwarded to the main site.
>>
>>  At the moment, my first VirtualHost is catching everything and
>> displaying
>> the standard homepage fine, but i'd much prefer if they were pushed
>> over to
>> the correct URI.
>
> Did you read the link I sent? That is exactly what it does.
>
> As it says, the first <VirtualHost> is the default host which catches
> all names that don't match any other virtualhost. Put a Redirect in
> that host pointing to your "canonical" vhost (the "correct URI"),
> which should be contained in a separate <VirtualHost> section.
>
> Joshua.
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server
> Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

Re: [users@httpd] Global Vhost/Redirect

Posted by Joshua Slive <jo...@slive.ca>.
On 5/18/07, Scott Wilcox <sc...@x0f.org> wrote:
>
>  Hey Joshua,
>
>  I think I was a little ambiguous with what I said. It probably would of
> been better to explain it like this.
>
>  If a VirtualHost is there for the requested URI, that is served.
>  For any requested URI (http://test1.com, http://sub.domain.com,
> http://anything.anythingelse.anywhere.tld), then that
> request is actually forwarded to the main site.
>
>  At the moment, my first VirtualHost is catching everything and displaying
> the standard homepage fine, but i'd much prefer if they were pushed over to
> the correct URI.

Did you read the link I sent? That is exactly what it does.

As it says, the first <VirtualHost> is the default host which catches
all names that don't match any other virtualhost. Put a Redirect in
that host pointing to your "canonical" vhost (the "correct URI"),
which should be contained in a separate <VirtualHost> section.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Global Vhost/Redirect

Posted by Scott Wilcox <sc...@x0f.org>.
Hey Joshua,

I think I was a little ambiguous with what I said. It probably would of
been better to explain it like this.

If a VirtualHost is there for the requested URI, that is served.
For any requested URI (http://test1.com, http://sub.domain.com,
http://anything.anythingelse.anywhere.tld), then that request is
actually forwarded to the main site.

At the moment, my first VirtualHost is catching everything and
displaying the standard homepage fine, but i'd much prefer if they were
pushed over to the correct URI.

Scott.


Joshua Slive wrote:
> On 5/18/07, Scott Wilcox <sc...@x0f.org> wrote:
>>
>>  Is there a method to say:
>>
>>  Requested URI:
>>  http://domain.com              Does nothing
>>  http://sub.domain.com       Redirects to http://domain.com
>>
>>
>>  It seems to me, if I used the Redirect Perm, it'd just loop around
>> itself,
>> no?
>
> http://wiki.apache.org/httpd/Recipes/CanonicalHostNames
>
> The sub.domain.com virtual host goes first and catches all non-matched
> names. The domain.com vhost goes last and does not contain a Redirect.
>
> Joshua.
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server
> Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>   "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

Re: [users@httpd] Global Vhost/Redirect

Posted by Joshua Slive <jo...@slive.ca>.
On 5/18/07, Scott Wilcox <sc...@x0f.org> wrote:
>
>  Is there a method to say:
>
>  Requested URI:
>  http://domain.com              Does nothing
>  http://sub.domain.com       Redirects to http://domain.com
>
>
>  It seems to me, if I used the Redirect Perm, it'd just loop around itself,
> no?

http://wiki.apache.org/httpd/Recipes/CanonicalHostNames

The sub.domain.com virtual host goes first and catches all non-matched
names. The domain.com vhost goes last and does not contain a Redirect.

Joshua.

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Global Vhost/Redirect

Posted by Scott Wilcox <sc...@x0f.org>.
Is there a method to say:

Requested URI:
http://domain.com              Does nothing
http://sub.domain.com       Redirects to http://domain.com


It seems to me, if I used the Redirect Perm, it'd just loop around
itself, no?

Scott.

Victor Trac wrote:
> In your catchall vhost (first one), just have a:
>
> Redirect permanent / http://main.uri.com
>
> --Victor
>
>
> On 5/18/07, *Scott Wilcox* <sc0tt@x0f.org <ma...@x0f.org>> wrote:
>
>     hey folks.
>
>     I have various virtual hosts set up on apache, and currently, the
>     first
>     <VirtualHost> handles all unreferenced domains. I'm looking at
>     implementing something to catch any unreferenced domains and actually
>     shoot a rewrite at them to point them to my actual main URI.
>
>     Is this possible, and what would be the best/most efficient way to
>     do it?
>
>     Thanks in advance,
>
>     Scott.
>
>     ---------------------------------------------------------------------
>     The official User-To-User support forum of the Apache HTTP Server
>     Project.
>     See <URL:http://httpd.apache.org/userslist.html> for more info.
>     To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>     <ma...@httpd.apache.org>
>        "   from the digest: users-digest-unsubscribe@httpd.apache.org
>     <ma...@httpd.apache.org>
>     For additional commands, e-mail: users-help@httpd.apache.org
>     <ma...@httpd.apache.org>
>
>
>
>
> -- 
> http://www.victortrac.com <http://www.victortrac.com>
> ------------------------------------------------------------------------
>
> No virus found in this incoming message.
> Checked by AVG Free Edition. 
> Version: 7.5.467 / Virus Database: 269.7.3/809 - Release Date: 17/05/2007 17:18
>   

Re: [users@httpd] Global Vhost/Redirect

Posted by Victor Trac <vi...@gmail.com>.
In your catchall vhost (first one), just have a:

Redirect permanent / http://main.uri.com

--Victor


On 5/18/07, Scott Wilcox <sc...@x0f.org> wrote:
>
> hey folks.
>
> I have various virtual hosts set up on apache, and currently, the first
> <VirtualHost> handles all unreferenced domains. I'm looking at
> implementing something to catch any unreferenced domains and actually
> shoot a rewrite at them to point them to my actual main URI.
>
> Is this possible, and what would be the best/most efficient way to do it?
>
> Thanks in advance,
>
> Scott.
>
> ---------------------------------------------------------------------
> The official User-To-User support forum of the Apache HTTP Server Project.
> See <URL:http://httpd.apache.org/userslist.html> for more info.
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
>    "   from the digest: users-digest-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>


-- 
http://www.victortrac.com