Forum Moderators: phranque
The company I work for has a SaaS application that we host on the web for our customers. One particular customer is reselling our services and has a special request: to host the same site using different URLs. This is for branding purposes so that their customers will see the correct company name in the URL when navigating to the site.
Our application is designed to use a single URL for interapp redirection and such, so I need to pick up the HTTP_REFERER and use that to determine whether the URL should be rewritten. I'm testing in QA with the following URLs: qa-ssdp01.boulder.api.local (which is the primary hostname) and qa-nametest.boulder.api.local (secondary hostname). Here's what I have in apache config:
ReWriteEngine On
ReWriteLog "/var/log/ssbe/apache/rewrite.log"
ReWriteLogLevel 9
ReWriteCond ${HTTP_REFERER} .*nametest.*
ReWriteRule ^/(.*) [dashboard.qa-nametest.boulder.api.local...] [R,L]
You first navigate to a login page (core.qa-nametest.boulder.api.local/login). After successful login, the app redirects to dashboard.qa-ssdp01.boulder.api.local, but I want to pick out that redirect and instead send it to dashboard.qa-nametest.boulder.api.local.
Has anyone done something like this before. I've tried every google keyword I can think of, but it keeps coming back with the same results.
This is the weak point of the whole system: HTTP clients are not required to send a referrer, and many "Internet security" software packages, corporate and ISP caching proxies (e.g. all of AOL, Earthlink, etc.) and some firewalls will suppress the HTTP Referer header.
This is a common problem often encountered with simple "anti-hotlinking" methods based on the HTTP Referer, and the fact that blank referrers must be allowed in order to avoid major problems with AOL, etc. represents a fairly-sizable "hole" in referrer-based anti-hotlinking methods.
Here the problem is more serious, in that encountering a blank referrer, you cannot make the decision about what to do with the request. Since the visitor may very well be unaware that his/her Referer headers are being suppressed, you also cannot ask the visitor to 'fix' anything.
As with anti-hotlinking, the solution may lie with using cookies to pass client-side information into the server reliably.
I'm not sure --given only one example-- of how you want the "mapping" to work in various circumstances, but the basic function can be demonstrated with something like:
RewriteCond %{HTTP_HOST} ^dashboard\.qa-ssdp01\.([^.]+)\.api\.local
RewriteRule ^/(.*)$ http://dashboard.qa-nametest.%1.api.local/$1 [R=302,L]
This code isn't meant to be a direct solution (since we still have the major issue of the HTTP Referer being unreliable), but it does demonstrate some of the "pieces and parts" of dealing with hostnames and URL-paths.
Going back to that referrer problem, be aware that mod_rewrite on Apache versions 1.3-2.x can test %{HTTP_COOKIE}, and mod_rewrite's RewriteRule directive has a "set cookie" function available in Apache 2.x (and presumably in later versions to come).
Jim