开发者

Setting referrer/header on a redirect in Apache

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 w开发者_如何学Goith 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):

  1. Allow Rails to handle the redirect for you, instead of Apache, and store some information in the user's session.

  2. Use the cookie RewriteRule 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.


For strictly performance reasons, I would stick with Apache doing the redirect so it doesn't need to go into the Rack (aka spend more time). Thus I would set a cookie on the RewriteRule and destroy the cookie once you detect the redirect.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜