Silent no-www flamboyancy

The whole www. or no-www. flamboywar is a bit dull. Anyhow, here is a tip that will configure Apache to inform users and search engines about the preferred location (aka. domain) of webpages.

Content-Location is a header from the HTTP standard that is intended to inform users about an alternate location of a resource without redirecting them.

The below scrip is placed in Apache’s /.htaccess configuration file. Apache 2.2.4 or newer required.

SetEnv absolutehost http://domain.tld/
SetEnvIfNoCase Host ^domain.tld$ absolutehosttrue=yes
SetEnvIfNoCase Request_URI \/(.*)\..* requesturi=$1
Header always unset Content-Location
Header always set Content-Location %{absolutehost}e%{requesturi}e env=!absolutehosttrue

To sum up what it does: It first stores the absolute host (domain name) in two enviromental variables. Then it checks whether the request was made from the absolute host or not, before it first unsets the Content-Location header and then sets the new header if the request was made from any host but the preferred host. Voila.

Copyright © 2008 Daniel Aleksandersen 2008-05-29 at 01:05

« Reply to “Making the World Wide Web an Easier Place to Talk About” | Home | Learning bash »

Leave your comment




Related entries Stay informed

Get a free subscription to new entries in the Open Source Notebook!

News feed icon Navigation

Runbox Runbox logo
  • 10 GB email storage,
  • 1 GB file storage,
  • 100 MB attachment limit,
  • your own domain,

...and more! Get your own premium email for just 49 USD per year!

Categories Archives

The archive keeps a record of all entries that have ever been published! Have a look back in time, and see what was going on!

License

This blog entry text is licensed under a Creative Commons Sampling Plus 1.0 License. The license explained, and legal notes.

Creative Commons Sampling+


Copyright © 2006–2008 Daniel Aleksandersen | Legal, license and trademarks | Privacy policy