I've setup some redirects on an Apache server. They look at bit like this:
Redirect /Name/register /login.html
My questi开发者_如何学Pythonon is this... is there anyway to preserve the HTTP Referrer through this redirect? It would seem that by default, Apache discards the information. I would really like it if after the redirect was complete the referrer was say:
http://the.orginalurl.com/Name/register
Anyone if this is even possible? If not, thoughts on an alternative.
Many thanks, Neil
Redirect
won't preserve the referrer because the browser is sent a 301 and a new address to open. From the manual:
The Redirect directive maps an old URL into a new one by asking the client to refetch the resource at the new location.
mod_rewrite and (I think) Alias can rewrite directly (i.e. without causing a browser redirect) and will preserve the referrer. With mod_rewrite, you can even add the referer as a GET parameter to your request, if you want to.
It's a browser issue, not apache. There isn't much you can do about it. This is done to prevent certain security issues and referrer spam.
http://en.wikipedia.org/wiki/HTTP_referrer#Referrer_hiding
You can always store the original referrer in a pipeline variable at the beginning of the request and just pull it from there instead.
I created an alternative way that transfers the refferer through a 301 redirect. https://webmasters.stackexchange.com/questions/4665/
I believe it all depends on how you write the rule. It can act as a "redirect" or a "rewrite" according to the flags you provide.
1. Redirect
302 will be sent to the browser, and it will initiate another request ( see Firebug with the "persist" option enabled ):
RewriteCond %{REQUEST_URI} !/index.html
RewriteRule ^(.*)$ /index.html [R=302,L]
2. Rewrite
browser does not initiate a 302 redirect because we don't send such header, but it will mask the content:
RewriteCond %{REQUEST_URI} !/index.html
RewriteRule ^(.*)$ /index.html [L]
In this option, if someone will access "page.html" he will see the content of "index.html" not "page.html" but the URL above will still show "page.html"
Good for maintenance page etc ... not sure about login pages ... but it's another option to think about.
The main difference between the "RewriteRule" vs "Alias" in my specific case, is that the rewrite can be set inside .htaccess while "Alias" does not ... so not always you can use Alias ...
精彩评论