I have a site with a short url domain with an A record pointing to the main site (it’s a pain to change this so I’d rather not). I have special logic that needs to run when the application is accessed from the short URL.
Right now, I have Apache set up with a RewriteRule to do a 301 to the main site when you hit the short URL, but if I try to access the referrer or any sort of headers they seem to be gone. I can get around this by appending a query parameter, but I’d rather not muddy up the URL as well. Any ideas on how to set some piece of data within Apache that I can access in my Rails app to tell if the request was a result of accessing the short URL?
As the referrer is entirely client-side, you only have two options (other than the query string):
Allow Rails to handle the redirect for you, instead of Apache, and store some information in the user’s session.
Use the
cookieRewriteRule option. RewriteRule has a cookie/CO option that allows you to send a Set-Cookie down to the browser, along with the redirect response. The format of the option is:cookie|CO=NAME:VAL:domain[:lifetime[:path]]. See the RewriteRule documentation for more details.