Rewriting & redirecting : Example: HTTP-to-HTTPS redirect
 
Example: HTTP-to-HTTPS redirect
Example.com is a business-oriented social media provider. Its clients require that attackers cannot fraudulently post comments. If an attacker can post while disguised as originating from the client’s business, as this could enable an attacker to ruin a business’s reputation.
To provide clients with protection from HTTP session hijacking tools such as Firesheep, Example.com wants to automatically redirect all HTTP requests to HTTPS. This way, before the client attempts to log in and exposes both their credentials and HTTP session ID to an eavesdropper, the response and subsequent requests are SSL/TLS encrypted, and thereby protected.
The Redirect HTTP to HTTPS option in the server policy configuration allows you to redirect all HTTP requests to equivalent URLs on a secure site.
Alternatively, you can create a rewriting rule that matches all HTTP requests, regardless of host name variations or URL, such as:
http://www.example.com/login
http://www.example.co.jp/
and redirects them to the equivalent URL on its secure sites:
https://www.example.com/login
https://www.example.co.jp/
This rewriting rule has 3 parts:
Regular expression that matches HTTP requests with any host name — (.*)
 
This regular expression should not match HTTPS requests, since it would decrease performance to redirect requests that are already in HTTPS.
Regular expression that matches requests with any URL in the HTTP header — ^/(.*)$
Redirect destination location that assembles the host name ($0) and URL ($1) from the request in front of the new protocol prefix, https://
See “What are back-references?”.
This could be configured via either the CLI or web UI.
CLI commands to implement this are:
config waf url-rewrite url-rewrite-rule
edit "http_to_https"
set action redirect
set location "https://$0/$1"
set host-status disable
set host-use-pserver disable
set referer-status disable
set referer-use-pserver disable
set url-status disable
config match-condition
edit 1
set reg-exp "(.*)"
set protocol-filter enable
next
edit 2
set object http-url
set reg-exp "^/(.*)$"
next
end
next
end
config waf url-rewrite url-rewrite-policy
edit "http_to_https"
config rule
edit 1
set url-rewrite-rule-name "http_to_https"
next
end
next
end
See also
Example: Full host name/URL translation
Rewriting & redirecting
Example: Rewriting URLs using regular expressions
Example: Rewriting URLs using variables
Regular expression syntax
What are back-references?
Cookbook regular expressions