Skip to content

Adding a custom querystring to response #39

Open
@oldtinroof

Description

@oldtinroof

I've got a simple 301 redirect to capture all non .com domains I have registered for my site as follows:

DOMAIN = 'www.mywebsite.com'

use Rack::Rewrite do
  r301 %r{.*}, "http://#{DOMAIN}$&", :if => Proc.new {|rack_env|
    rack_env['SERVER_NAME'] != DOMAIN && ENV["RACK_ENV"] == 'production'
  }
end

I'd like to add a querystring to the response to add the original requested domain in the format so that I can track what domains people are hitting.

?utm_source=#{rack_env['SERVER_NAME']}
But can't quite work out how not to crash the server :) Can it be done & retain any original query string?

It's unlikely that anyone will hit any subpages under the main domain, but when I drop the $& from the rewrite, and replace it with my string, it blows up with no errors in the logs...

*nb: I asked this on SO a week ago with no replies, so I thought I'd post here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions