Discussion:
httpd - conditional redirects
t***@gmail.com
2021-04-29 00:45:33 UTC
Permalink
Hope I'm putting this in the appropriate mailing list.

A minor (I hope) potential feature request for httpd:

I wish to redirect clients not from a certain IP (e.g. my public IP at
home) to a different location, temporarily. The purpose of this is to
allow setting up a "maintenance" page so that I can properly test my
site with a piece of mind before actually making it available to
other visitors. I personally consider this a crucial ability.

The way I would usually solve it via Apache is to use RewriteCond and
RewriteRule. For httpd, however, it could suffice to implement a simple
"redirect" directive maybe:

redirect [not] <ip-address> to <uri>

I could then accomplish what I want using two location blocks:

location match "^/maintenance.html$" {
  root "/htdocs/example.com/maintenance"
}
location match ".*" {
  redirect not my.ho.me.ip to scheme://host/maintenance.html
}

I warmly welcome other ideas to accomplish this as well.

Thanks.
Tim Baumgard
2021-04-29 01:36:16 UTC
Permalink
Post by t***@gmail.com
.....
redirect [not] <ip-address> to <uri>
location match "^/maintenance.html$" {
root "/htdocs/example.com/maintenance"
}
location match ".*" {
redirect not my.ho.me.ip to scheme://host/maintenance.html
}
I can’t speak for the OpenBSD developers, but I personally don’t think
this would be generally useful. However, I can maybe give you some
advice on how to accomplish what you want without any changes to httpd.

Back before httpd included what it does today, I used to use a "shim"
that I created to customize HTTP requests to do whatever I needed, even
if the application I was using didn't work due to a lack of some
features in httpd. In my case, it was a PHP file that would modify the
request and then pass everything on to whatever application. I set up a
match rule in httpd.conf that would match anything and set it to call
that shim, which would then dispatch things as needed.

So, some pseudo code for a shim for your instance:

if (isInMaintenanceMode && ipAddress != myIpAddress) {
// output the maintenance page
} else {
// load the normal app
}

Hopefully you can figure out something that will work for your
situation.

Tim
ITwrx
2021-04-29 01:06:31 UTC
Permalink
Post by t***@gmail.com
Hope I'm putting this in the appropriate mailing list.
I wish to redirect clients not from a certain IP (e.g. my public IP at
home) to a different location, temporarily. The purpose of this is to
allow setting up a "maintenance" page so that I can properly test my
site with a piece of mind before actually making it available to
other visitors. I personally consider this a crucial ability.
The way I would usually solve it via Apache is to use RewriteCond and
RewriteRule. For httpd, however, it could suffice to implement a simple
redirect [not] <ip-address> to <uri>
location match "^/maintenance.html$" {
  root "/htdocs/example.com/maintenance"
}
location match ".*" {
  redirect not my.ho.me.ip to scheme://host/maintenance.html
}
I warmly welcome other ideas to accomplish this as well.
Thanks.
one way to accomplish this is to put your testing site on a subdomain
and the maint page on the main domain. only allow your ip to the testing
subdomain. allow all to maint domain. when done testing, swap things
out. there may be a way to block/allow with existing rewrite
rules/features, but i'm not very experienced with httpd and relayd, so i
would have to look it up, and i'm too lazy for that right now. :)
gwes
2021-04-29 02:47:28 UTC
Permalink
Post by t***@gmail.com
Hope I'm putting this in the appropriate mailing list.
I wish to redirect clients not from a certain IP (e.g. my public IP at
home) to a different location, temporarily. The purpose of this is to
allow setting up a "maintenance" page so that I can properly test my
site with a piece of mind before actually making it available to
other visitors. I personally consider this a crucial ability.
pf (4) is happy to redirect anywhere, anywhen.

  2nd httpd on another machine listening on standard ports
or
  2nd httpd on same machine listening on chosen nonstandard ports

redirect in gateway

or
  1 httpd listening on outside address
  1 httpd listening on internal address
pf on server redirects as necessary

or

use testing.yourdomain.whatever if you can

or

play fast and loose with a schizo name server:
   server.yourdomain is served by an outside nameserver
   server.yourdomain is intercepted by your local nameserver

or...

some of these won't work for you
somebody else can think up more

Geoff Steckel

Loading...