On Fri, 15 May 2015, Karl Holten wrote:
> My organization is changing proxy servers from WAM to EZproxy, and we would like to give staff time to change over their URLs before we make the switch. I would like to set up forwarding so the links using the new proxy get redirected to the old proxy. I'm planning on using apache's mod_rewrite to do this.
>
> Basically, this mod rewrite rule needs to do three things:
> 1) Change the part of the domain name (not the file path) that reads "ezproxy.switchinc.org" to our old domain "topcat.switchinc.org"
> 2) Append the prefix "0-" in front of the domain name
> 3) Transform dashes in the domain name to periods.
>
> Could anyone provide me with some assistance? I am sure this takes maybe
> 10 lines of code from a mod_rewrite expert, but it has taken me several
> weeks to the first two objectives done, and all of my google fu is
> failing me for objective three. Below is what I have:
>
> RewriteEngine on
> RewriteCond %{HTTP_HOST} ^(.*)ezproxy.switchinc.org [NC]
> RewriteRule ^(.*) %{HTTP_HOST}/$1 [DPI]
> RewriteRule ^(.*)ezproxy.switchinc.org/(.*) http://0-$1topcat.switchinc.org/$3 [L]
The problem with number three is that you don't know how many dashes there
are that need to be changed to periods, so you have to use [N], and can't
use it in a chain. I'm actually going to re-arrange it to 1,3,2, so we
can leave the [L] on the #2 (in case you had any other rules that might
mess with it).
It also seems suspicious that you'd insert a '0-' when you're then going
to be replacing all of the dashes with periods -- especially as I don't
believe that '0' is a valid host name in DNS. I've assumed that the '0-'
stays ... otherwise, replace it with '0.'
Also note that I changed your #2 from using $3 to $2 -- you only had two
sets of capturing parens.
RewriteCond %{HTTP_HOST} ^(.*)ezproxy.switchinc.org [NC]
RewriteRule ^(.*) %{HTTP_HOST}/$1 [DPI]
RewriteRule ^(.*)-(.*)ezproxy.switchinc.org/(.*) $1.$2ezproxy.switchinc.org/$3 [N]
RewriteRule ^(.*)ezproxy.switchinc.org/(.*) http://0-$1topcat.switchinc.org/$2 [L]
If we assume that the FQDN only contains numbers, letters, dashes and
periods (no underscores or other characters), you might check how the
first one compares to:
RewriteRule ^([a-zA-Z0-9\.]+)-([a-zA-Z0-9\.\-]*)ezproxy.switchinc.org/(.*) $1.$2ezproxy.switchinc.org/$3 [N]
... and note that I haven't tested this -- it should work, but with [N],
you run the risk of endless loops.
-Joe
ps. Back in the days when I used to manage the spam filters for an
ISP, domain names that tried to look like IP addresses were one of my
rejection rules, which it's possible that your site might look like.
://(\d+\.){4]
I know, you're wondering why I don't have http:// or https?:// ...
because this was so old, people were still hosting spam on FTP
servers. Also note that there is (was?) an ad company that was
serving ads from something that looked like a numeric (1o8 ? lo8) and
then prepended 3 numeric blocks before it, so it looked like an IP
address, but wouldn't have been caught by this rule).
|