The Upgrade-Insecure-Requests HTTP header plays a key role in modern web security by encouraging secure connections between clients and servers. Although it is technically a request header, it has significant implications for overall security and how web servers handle requests.
Upgrade-Insecure-Requests is an HTTP request header that informs the server a client is capable of handling—and prefers—an encrypted (HTTPS) version of the requested resource. When this header is sent, the browser is effectively signaling that it supports upgrading any non-secure (HTTP) links to secure (HTTPS) links.
Upgrade-Insecure-Requests: 1
The browser or client includes an Upgrade-Insecure-Requests: 1 header in its HTTP request.
Upon receiving this header, the server recognizes that the client can handle a transition to HTTPS.
If the requested resource is not already served via HTTPS, the server can issue a redirect (3xx) to the secure version.
The server can set Vary: Upgrade-Insecure-Requests to differentiate between users who can be upgraded.
<VirtualHost *:80>
ServerName example.com
RewriteEngine On
# Check if the Upgrade-Insecure-Requests header is set to 1
RewriteCond "%{HTTP:Upgrade-Insecure-Requests}" "1"
# Redirect to HTTPS if the condition matches
RewriteRule "^/(.*)" "https://example.com/$1" [R=301,L]
# You can also set the Vary header to ensure proper caching
Header add Vary "Upgrade-Insecure-Requests"
</VirtualHost>
server {
listen 80;
server_name example.com;
# Redirect to HTTPS if the header is set
if ($http_upgrade_insecure_requests = 1) {
return 301 https://example.com$request_uri;
}
# Additional server configuration goes here
}
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="UpgradeInsecureRequestsRedirect" stopProcessing="true">
<match url="(.*)" ignoreCase="true" />
<conditions>
<add input="{HTTP_UPGRADE_INSECURE_REQUESTS}" pattern="1" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}"
redirectType="Permanent" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Failing to respond with an HTTPS version leaves data traveling over an insecure channel.
When HTTP connections remain unencrypted, attackers can intercept session cookies or tamper with data.
Without considering this header, you lose insight into which clients prefer secure upgrades.
Learn about other HTTP security headers to strengthen your website's security: