Better way to do Apache hostname redirects than this?

Better way to do Apache hostname redirects than this?

Post by Ed Thomps » Fri, 06 Sep 2002 06:25:55



I work for a company that has over 350 stores. Each store will have
its own URL:

<storenumber>.<mycompany>.com that redirects to a specific URL on our
main web site.

What I am planning to do right now is to add over 350 VirtualHost
entries to the Apache httpd.conf file like this:

<VirtualHost *>      
ServerName 111.mycompany.com
Redirect / http://www.mycompany.com/store.jsp?store=111
</VirtualHost>

<VirtualHost *>      
ServerName 222.mycompany.com
Redirect / http://www.mycompany.com/store.jsp?store=222
</VirtualHost>

Is this the most efficient method to do this? Can I use Rewrites?
Since the hostname and redirect URL follow the same pattern, I am
hoping I can do something more dynamic than to manually add an entry
for each store we have - since store numbers do change from time to
time. I thought I read that rewriting might help me with this problem.

Ideas, please! I am no expert. Thank you in advance!

 
 
 

Better way to do Apache hostname redirects than this?

Post by Patrick Vie » Fri, 06 Sep 2002 08:50:06


apache must be compiled with mod_rewrite
( ./configure --with-module=rewrite )

<VirtualHost *>
ServerName 1.mycompany.com
ServerAlias *.mycompany.com

Rewri*gine On
RewriteCond %{HTTP_HOST} !^www\.mycompany\.com$
RewriteRule (.*)\.mycompany.com www.mycompany.com/store.jsp?store=$1
</VirtualHost>

--
Patrick Viet - Azuria Hosting : http://www.veryComputer.com/

 
 
 

Better way to do Apache hostname redirects than this?

Post by D. Stuss » Fri, 06 Sep 2002 10:45:40



Quote:>I work for a company that has over 350 stores. Each store will have
>its own URL:

><storenumber>.<mycompany>.com that redirects to a specific URL on our
>main web site.

>What I am planning to do right now is to add over 350 VirtualHost
>entries to the Apache httpd.conf file like this:

><VirtualHost *>
>ServerName 111.mycompany.com
>Redirect / http://www.mycompany.com/store.jsp?store=111
></VirtualHost>

><VirtualHost *>
>ServerName 222.mycompany.com
>Redirect / http://www.mycompany.com/store.jsp?store=222
></VirtualHost>

>Is this the most efficient method to do this? Can I use Rewrites?
>Since the hostname and redirect URL follow the same pattern, I am
>hoping I can do something more dynamic than to manually add an entry
>for each store we have - since store numbers do change from time to
>time. I thought I read that rewriting might help me with this problem.

>Ideas, please! I am no expert. Thank you in advance!

Yes, the rewrite engine leads to a more efficient solution.  See newsgroup
"alt.apache.configuration" - there was a thread on this about 2 months ago.
 
 
 

Better way to do Apache hostname redirects than this?

Post by D. Stuss » Fri, 06 Sep 2002 10:47:23



>apache must be compiled with mod_rewrite
>( ./configure --with-module=rewrite )

><VirtualHost *>
>ServerName 1.mycompany.com
>ServerAlias *.mycompany.com

>Rewri*gine On
>RewriteCond %{HTTP_HOST} !^www\.mycompany\.com$
>RewriteRule (.*)\.mycompany.com www.mycompany.com/store.jsp?store=$1
></VirtualHost>

Note that this may work with Apache 2.0, but not with 1.3.  URL-URL rewriting
isn't permitted under version 1.3 (URL->File is allowed).
 
 
 

Better way to do Apache hostname redirects than this?

Post by Ed Thomps » Fri, 06 Sep 2002 21:19:20


What are my options under Apache 1.3? The VirtualHost entries I used
as an example don't work after all:

<VirtualHost *>
ServerName 111.mycompany.com
Redirect / http://www.mycompany.com/store.jsp?store=111
</VirtualHost>

The above entry causes problems in Apache 1.3. If I type
222.mycompany.com, it goes to the 111.mycompany.com page instead. I
believe I am misusing the VirtualHost * entry.

Can someone post the proper syntax for this hostname redirects under
Apache 1.3?

Thank you!



> >I work for a company that has over 350 stores. Each store will have
> >its own URL:

> ><storenumber>.<mycompany>.com that redirects to a specific URL on our
> >main web site.

> >What I am planning to do right now is to add over 350 VirtualHost
> >entries to the Apache httpd.conf file like this:

> ><VirtualHost *>
> >ServerName 111.mycompany.com
> >Redirect / http://www.mycompany.com/store.jsp?store=111
> ></VirtualHost>

> ><VirtualHost *>
> >ServerName 222.mycompany.com
> >Redirect / http://www.mycompany.com/store.jsp?store=222
> ></VirtualHost>

> >Is this the most efficient method to do this? Can I use Rewrites?
> >Since the hostname and redirect URL follow the same pattern, I am
> >hoping I can do something more dynamic than to manually add an entry
> >for each store we have - since store numbers do change from time to
> >time. I thought I read that rewriting might help me with this problem.

> >Ideas, please! I am no expert. Thank you in advance!

> Yes, the rewrite engine leads to a more efficient solution.  See newsgroup
> "alt.apache.configuration" - there was a thread on this about 2 months ago.

 
 
 

Better way to do Apache hostname redirects than this?

Post by Ed Thomps » Sun, 08 Sep 2002 04:59:45


Patrick Viet sent me the solution for Apache v1.3 (and presumably also
Apache v2.0) and it works GREAT. I am posting here for the benefit of
anyone else who may run into this problem in the future and stumbles
across this post...

<VirtualHost *>
    ServerName virtual.mycompany.com
    ServerAlias *.mycompany.com
    Rewri*gine On
    RewriteRule ^(.*)$ /rewrite%{HTTP_HOST}
    RewriteRule ^\/rewrite(.*)\.mycompany\.com
http://www.veryComputer.com/$1 [R]
</VirtualHost>

(The second RewriteRule is on one line, but it's wrapping in the
USENET post because it's so long)

Patrick, thanks for everything!

 
 
 

1. Better Apache Redirect?

Hey y'all,

I'm running Apache v1.1b on our machine and need to do some minor
redirecting.  What I'd like to do is take a request such as:

        /cgi/steve/foo.pl

and redirect it to:

        /cgi-bin/cgiwrap/steve/foo.pl

which is the correct URL.  Now, I know I could use the 'Redirect' command
but it seems more oriented towards redirecting browsers to other sites
rather than other places on the local system.  I'd like to be able to
essentially change "/cgi/" in any URL passed to me to "/cgi-bin/cgiwrap/"
and THEN have Apache process it.  Is there any way to do this?

-S
--
Steve Bernacki, Jr. | Assistant System Administrator, zipnet.net

2. Initialization/Load order of shared libraries

3. i know there are better ways....

4. APACHE AND BSDI

5. Apache Redirect/ReWrite for redirecting old->new domains?

6. Home Network with Cable Modem and SUSE 7.0

7. How do i disable all ways to get access to the dos prompt on startup?

8. HP Printing to Solaris

9. How do i disable all ways to get access to the dos prompt on sta

10. Different ways of doing the same thing?

11. redirecting to different hostname and dropping query string

12. Redirects based on remote hostname?

13. Forbid or redirect depending on hostname