I have two subdomains, let’s call them x.example.com and y.example.com. When a user requests x.example.com, the server redirects them to y.example.com.
On y.example.com, there’s a feature that displays specific content if the referer header matches a certain value. However, when the request comes to y.example.com after the redirection, it doesn’t have any referer header attached to it.
I’m using Django on the backend to handle the redirection with HttpResponseRedirect(“y.example.com”).
I attempted to include the referer header in the server’s response using Django, but it didn’t seem to have any effect.
response = HttpResponseRedirect("y.example.com")
response['referer'] = 'https://x.example.com'
Additionally, I tried implementing a redirection in JavaScript by returning HTML with embedded JavaScript code, but that also didn’t result in the referer header being passed along. Interestingly, directly executing the JavaScript redirection in the browser console did include the referer header. I’m puzzled as to why it’s not working as expected. Can you suggest an alternative approach to achieve the desired behavior?
html_content = """
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Redirecting...</title>
</head>
<body>
<h1>Redirecting...</h1>
<script>
// JavaScript code for redirection
window.location.href = 'https://y.example.com';
});
</script>
</body>
</html>
"""
# Return the HTML response with embedded JavaScript
return HttpResponse(html_content)
Yash Nigam is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.