Apache trailing slash problem for multiple rewrites
I'm trying to proxy multiple instances of a web application (Nagios) on multiple remote machines via one Apache proxy machine.
In a virtual host definition, I've created separate Location entries for each instance, since each has a different authentication mechanism. And for each Location, I've created a set of RewriteRule directives, like the following: Code:
RewriteRule ^/instance1$ /instance1/ [R] Code:
#Reverse proxy: |
Hi
I'm no expert on this, but why not just make 2 rules. One without a slash and one with: Code:
RewriteRule ^/instance1$ https://remote.url/and/path [L,P] |
Quote:
Maybe someone can make some sense of what is happening; the request here is for the URL '/instance' (no trailing slash): Code:
(2) init rewrite engine with requested uri /instance Viewing the resulting page source confirms that the trailing slash was not added, and that the URL remains unchanged. Also, the resultant page, though blank, is actually a "no frames" page (which includes a hidden comment that says "This page requires a web browser which supports frames"). And the Apache access log shows GETs for /instance instead of /instance/ (and for /favicon.ico too, which should be /instance/favicon.ico). |
I could still use some help with this: nothing I can think of trying seems to work.
|
I had to do the exact same thing. I had some trouble, but got it to work.
I know this is an old thread, but if anyone comes across it while trying to do this and wants me to post my configuration I'd be happy to. |
Quote:
|
Quote:
Either use duplicate rules like Code:
RewriteRule ^/instance1$ https://remote.url/and/path/ [L,P] Code:
RewriteRule ^/instance1$ /instance1/ [N] If the corrective rules are as simple as above, or you are very careful, the restart feature is immensely useful. Note that corrective rules that restart the chain are best used first, to make it as efficient as possible. If you are careful like me, you can even kill some path trickery at the same time. Consider using these as your very first rules: Code:
RewriteEngine on
Since browsers only allow a small number of redirects before giving up a query, it's best to apply all known fixes first, and then do a single redirect. If these rules are the very first ones, this is extremely efficient -- even a very high load site would not be able to measure the impact (other than the single redirect done). The end result is simple and safe for your other redirects; you won't need any duplicate rules et cetera. These also increase script security, since scripts never get paths with potentially nasty path walking components (/../ for example). Hope you find this useful, Nominal Animal |
All times are GMT -5. The time now is 06:30 PM. |