- Code: Select all
# These SetEnvIf statements get evaluated per request, before the
# Rewrite* statements. The Header statement sets a cookie to
# remember the visitor's original referrer until the visitor submits the
# contact form.
SetEnvIf Request_Method ".*" set_referrer_url_from_http_referer
SetEnvIf Referer "^$" !set_referrer_url_from_http_referer
SetEnvIf Referer "^http://(www\.)?mydomain\.com"
!set_referrer_url_from_http_referer
SetEnvIf Request_URI "^/vanity_url/" !set_referrer_url_from_http_referer
Header add Set-Cookie "original_referrer_url=%{HTTP_REFERER}e;
domain=.mydomain.com" env=set_referrer_url_from
# The Rewrite* statements are needed to handle the case when
# vanity URLs are used. Vanity URLs are of the form
# www.mydomain.com/abc. A vanity URL of the form /(abc) gets remapped
# to /vanity_url/abc.html, etc.... The original referrer information is
# also retained, which is important because if we simply did it in the
# SetEnvIf and Header section above, the referrer would be lost because
# the rewrite causes an internal redirect, which causes the referrer
# HTTP header to be lost.
RewriteEngine on
RewriteBase /
RewriteCond "/home/mydomain/www/public_html/vanity_url/$1.html" -s
RewriteCond "%{HTTP_REFERER}" "^http://(.+)$"
RewriteRule "^([a-zA-Z0-9]+)$" "vanity_url/$1.html"
[CO=original_referrer_url:%1:.mydomain.com,L]
RewriteCond "/home/mydomain/www/public_html/vanity_url/$1.html" -s
RewriteRule "^([a-zA-Z0-9]+)$" "vanity_url/$1.html" [L]
When I said the original configuration setting did not work, I meant that it did
not set the cookie as I wanted. Regardless, now I have my problem resolved in a
good way. however, I think cookie flag of the RewriteRule directive does not
allow environment variables. If it were consistent, you would think that the
cookie flag should allow environment variables.