Configuring an Apache server for Memento
1. HTTP Headers Using .htaccess
RewriteEngine On
RewriteRule ^(.*) - [E=ORIGPROTO:http]
RewriteCond %{HTTPS} on
RewriteRule ^(.*) - [E=ORIGPROTO:https]
RewriteRule ^(.*) - [E=ORIGURI:%{HTTP_HOST}]
RewriteCond %{THE_REQUEST} \s/+([^\s?]+)
RewriteRule ^ - [E=ORIGQRY:%1]
Header always set Link "<http://purl.org/memento/timegate/%{ORIGPROTO}e://%{ORIGURI}e%{ORIGQRY}e>;rel=timegate"
See: htaccess - how to capture the current rewrited url?
2. HTTP Headers Using PHP
function get_canonical_url($proto='http://'){
$canonical_url = $proto;
if($_SERVER["SERVER_PORT"] != "80") {
$canonical_url .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
}
else {
$canonical_url.=$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $canonical_url;
}
header('Link: <'.get_canonical_url().'>; rel="canonical"');
Resources: http://moz.com/blog/how-to-advanced-relcanonical-http-headers