HTTP Redirects with Cloudfront & S3
Posted on Tue 18 August 2015 in aws • Tagged with aws, cloudfront, s3, http
Redirects can account for a significant share of direct traffic so taking a few minutes to optimize them is worthwhile.
Using Cloudfront & S3 for redirects will improve responsiveness, reduce server load and improve management (since they are managed via aws-cli
or the console).
Let's say you have a typical .htaccess
redirect like this.
RewriteEngine On
### re-direct to www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Or worse, it could look like this in your index.php
$protocol = (@$_SERVER["HTTPS"] == "on") ? "https://" : "http://";
if (substr($_SERVER['HTTP_HOST'], 0, 4) !== 'www.') {
header …