httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From andrea <apachel...@libero.it>
Subject Re: [users@httpd] In Rewrite Loop -- please help
Date Thu, 11 Sep 2003 08:34:18 GMT
Hi timothy,
I'm answering to your first post :-)

> WORKING CONF
> 
> ### Section 3: Virtual Hosts
> 
> NameVirtualHost *
> 
> # main vhost
> <VirtualHost *>
>     ServerName www.mycity.com
>     ServerAlias mycity.com  *.mycity.com
> 
>     DocumentRoot "C:/usr/local/apache2-01/htdocs/mycity"
>     RewriteEngine on
>     RewriteCond %{HTTP_HOST} !^www.mycity.com [nocase] [OR]
>     #For internal use, prevents images from being blocked
>     RewriteCond %{HTTP_HOST} !^10\.*
>     RewriteCond %{HTTP_HOST} !^$
>     RewriteRule ^/(.*) http://www.mycity.com/$1 [R=permanent]
>     RewriteLog logs/rewrite.log
>     RewriteLogLevel 0
> </VirtualHost>
> 
Uhmm, it will work but I want to point put some notes.

Example:
 > RewriteCond %{HTTP_HOST} !^www.mycity.com [nocase] [OR]
The [OR] flag will be *ignored* by mod_rewrite.
If you need to use more flags use [nocase,OR] and *not* [nocase] [OR],
because in your example only nocase will be used by mod_rewrite.

Also it is a good pratice to escape the dots as www\.mycity\.com,
but that's a minor issue ;-).

Again you need to add a $ (``end of string''') because
^www\.mycity\.com
will match
www.mycity.com but www.mycity.com.au , etc too
^www\.mycity\.com$ will only match www.mycity.com

^10\.*
will match 10 10. 100 10etcetc
^10\.
will match 10. 10.0 10.etc which is a little better,
even if not all complete

Sorry but I thought interesting making those notes,
so I'd change your working conf as:

#*********WORKING, modified: begin
#etc
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mycity\.com$ [nocase]
#For internal use, prevents images from being blocked
RewriteCond %{HTTP_HOST} !^10\.
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.mycity.com/$1 [R=permanent]

 > <VirtualHost *>
 >     ServerName www.mycityevents.com
 >     ServerAlias mycityevents.com  *.mycityevents.com
 >     DocumentRoot "C:/usr/local/apache2-01/htdocs/mycity"
 >     RewriteEngine on
 >     RewriteCond %{HTTP_HOST} ^www.mycityevents.com [nocase]
 >     RewriteRule ^/(.*) http://www.mycityevents.com/rec/ [R=permanent]
 >     RewriteLog logs/rewrite_rec.log
 >     RewriteLogLevel 9
 > </VirtualHost>
 >
Nope, I don't think this works.
You will create an infinite 30x redirection loop.
SO I think you will have to use:
#etc
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mycityevents\.com$ [nocase]
RewriteRule ^/(.*) http://www.mycityevents.com/rec/ [R=permanent]
#*********WORKING, modified: end
I added a ! to avoid the ad-infinitum 30x loop


Let's back to your new httpd.conf:

> ***** BROKEN, LOOPY CONF ****
> 
> NameVirtualHost *
> 
> <VirtualHost *>
>     ServerName www.mycitystate.gov
>     ServerAlias mycitystate.gov  *.mycitystate.gov
> 
>     DocumentRoot "C:/usr/local/apache2-01/htdocs/mycity"
>     RewriteEngine on
>     RewriteCond %{HTTP_HOST} !^www.mycitystate.gov [nocase] [OR]
>     #For internal use, prevents images from being blocked
>     RewriteCond %{HTTP_HOST} !^10\.*
>     RewriteCond %{HTTP_HOST} !^$
>     RewriteRule ^/(.*) http://www.mycitystate.gov/$1 [R=permanent]
>     RewriteLog logs/rewrite.log
>     RewriteLogLevel 0
> </VirtualHost>
> 
Use:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mycitystate\.gov$ [nocase]
#For internal use, prevents images from being blocked
RewriteCond %{HTTP_HOST} !^10\.
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.mycitystate.gov/$1 [R=permanent]


> <VirtualHost *>
>     ServerName www.mycityevents.com
>     ServerAlias mycityevents.com  *.mycityevents.com
>     DocumentRoot "C:/usr/local/apache2-01/htdocs/mycity"
>     RewriteEngine on
>     RewriteCond %{HTTP_HOST} ^www.mycityevents.com [nocase]
>     RewriteRule ^/(.*) http://www.mycityevents.gov/rec/ [R=permanent]
>     RewriteLog logs/rewrite_rec.log
>     RewriteLogLevel 0
> </VirtualHost>
Use:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mycityevents\.com$ [nocase]
RewriteRule ^/(.*) http://www.mycityevents.gov/rec/ [R=permanent]



That should work.
Hope I didn't bored you too much but I thought correct to point out
the few mistakes I founded.



Thanks,
Mr Andrea

p.s.
I din't read your third post...it was too long! ;-)


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


Mime
View raw message