On Fri, 21 Jul 2006, Michael Glaser wrote:

> Mike Miller wrote:
>> On Fri, 21 Jul 2006, Michael Glaser wrote:
>> 
>>> Problem: Need to redirect 'www.domain.name/xy' to 'xy.other.domain.net'.
>>>
>>> Armed with my very limited knowledge of regular expressions and 
>>> mod_rewrite, I tried the following two configurations (one at a time) 
>>> and neither worked:
>>> 
>>>  RewriteCond %{REQUEST_URI}   ^/[xX][yY]/(.*) [NC]
>>>  RewriteRule ^/[xX][yY]/(.*)  http:/xy.other.domain.net/$1 [R=301,L]
>
>> You're sure that first one didn't work?
>
> Upon further testing, yes and no. With the expression listed above, here  is 
> what happens:
>
> www.domain.name/xy  -->  xy.other.domain.net/
> www.domain.name/XY  -->  error
> www.domain.name/XY/ -->  xy.other.domain.net/
> www.domain.name/xY  -->  error
> www.domain.name/xy/ -->  xy.other.domain.net/
> www.domain.name/Xy  -->  error
> www.domain.name/Xy/ -->  xy.other.domain.net/
>
> www.domain.name/xy/about  -->  xy.other.domain.net/about (works!)
>
> The first URL (all lowercase) works without a trailing slash, but not 
> the others. I wonder why this is happeing.

Of course you've discovered the problem.  I didn't know you wanted to 
forward if there was no final slash, but you do, and that is the problem. 
The first one shouldn't work, but I think you might have another rule in 
your file for xy that you have forgotten.

So I think you want two rules:

RewriteCond %{REQUEST_URI}   ^/[xX][yY]/(.*) [NC]
RewriteRule ^/[xX][yY]/(.*)  http:/xy.other.domain.net/$1 [R=301,L]

RewriteCond %{REQUEST_URI}   ^/[xX][yY] [NC]
RewriteRule ^/[xX][yY]  http:/xy.other.domain.net/ [R=301,L]


The problem with your idea here...

>  RewriteCond %{REQUEST_URI}  ^/[xX][yY](.*) [NC]
>  RewriteRule ^/[xX][yY](.*)  http:/xy.other.domain.net/$1 [R=301,L]

...is that it will work for /xyfoo and you don't want it to do that.


> Now this gets me even closer to exactly what I wanted. I removed the 
> last '/' in the expression. Now when the URL ends in 'xy' in any 
> combination of case, the desired page appears 'xy.other.domain.net/'.
>
> If I include a trailing slash in the original request, the URL in the 
> redirected page include an extra one at the end of the address, but the 
> page does open. It would look like this:
>
> www.domain.name/xy/  -->  xy.other.domain.net//
>
> Much closer, and this is probably good enough, but not exactly correct. 
> Is there an easy way to solve this?

I think my recommendation will work.

Mike