Op Tue, 14 Dec 2004 21:44:24 +0000, schreef Jonathan:
> I'm using Apache 1.3 and want to redirect some URLs to other URLs on a
> different server.
> So, at first I used:
<font color=purple> > Redirect permanent /www2 <a style='text-decoration: underline;' href="http://10.10.10.103</font" target="_blank">http://10.10.10.103</font</a>>
<font color=purple> > Redirect permanent /another <a style='text-decoration: underline;' href="http://10.10.10.103</font" target="_blank">http://10.10.10.103</font</a>>
> That worked fine.
> But then I realised that some requests are going to be coming from
> public IP addresses (and not just the VPN as I first thought). Those
> people need to be redirected to the public IP of the server, and the VPN
> people can't see that.
> So I tried:
>
> RewriteCond %{REMOTE_ADDR} ^10.10\10.*
> RewriteRule ^/www2 <a style='text-decoration: underline;' href="http://10.10.10.103" target="_blank">http://10.10.10.103</a> [L]
>
> RewriteCond %{REMOTE_ADDR} !^10.10.10.*
> RewriteRule ^/another <a style='text-decoration: underline;' href="http://217.205.135.185" target="_blank">http://217.205.135.185</a> [L]
>
> But that doesn't work. Not only does everyone get directed to the
> private IP, but I don't think the redirect rule is going to redirect
> along the path, so /www2/foo/bar isn't going to go to
> <a style='text-decoration: underline;' href="http://10.10.10.103/foo/bar" target="_blank">http://10.10.10.103/foo/bar</a> as I want it to do.
>
Taking a look at your rewrite directives, I think you can sharpen them a
bit. If I understand it correctly, These should be:
RewriteCond &{REMOTE_ADDR} ^10\.10\.10\..*
RewriteRule ^/www2/(.*) http://10.10.10.103/$1 [L]
RewriteCond &{REMOTE_ADDR} !^10\.10\.10\..*
RewriteRule ^/another/(.*) http://217.205.135.185/$1 [L]
There are two things differently to your approach:
- in a regex, a dot (.) matches any character. If you want to match as a
dot, you have to escape it. eg \.
- you want everything that comes after /www2 to be appended to the new
address. This is done by capturing any character that comes after that
[-> /www2/(.*)], and appending it to the new constructed address with $1.
I haven't tried this, so I'm not sure it'll work, but you can give it a
go.
-leendert bottelberghs<!-- ~MESSAGE_AFTER~ -->
>> Stay informed about: Directing Hosts to Different URLs?