« i never wanna wake up alone any more | Main | how to keep vpn working »

redirecting a server via mod_rewrite

i am administering a page for an association which is hosted by a university. the address is http://www.my-university.tld/association/. because this is annoying to type, we registered the domain association.tld to provide direct access. but the regulations (dt: reglement) do not allow the computer department to host any other domains on the university's servers.

so i found a webhost provider who hosts us the domain, only to redirect it to the university page. up to now we used to redirect with a html tag in the header:
http-equiv="refresh"
content="0;URL=http://www.my-university.tld/association/">

this solution works, but i is not very elegant, because:
  1. the page with the redirection has to be loaded first, it slows down the process
  2. the redirection page will be displayed for a moment (though only for a short moment it is unnecessary)
  3. any file or folder request except the association.tld/index.html will result in a 404 file not found error.

to find a more elegant solution, i looked at the apache rewrite mod. it is sort of hard to understand, but after looking around a little i found a solution:
RewriteEngine On
RewriteRule ^(.*) http://www.my-university.tld/association/$1 [R]

this is the text to place in the .htaccess file in the root folder of the association.tld server. now, every request for a file on association.tld will be forwarded, for example www.association.tld/folder/file.html will go directly to
www.my-university.tld/association/folder/file.html.

some resources to the topic of the mod_rewrite:
Module mod_rewrite URL Rewriting Engine
Apache 1.3 URL Rewriting Guide
mezzoblue § rewrite! (see also comments)
mactechnews.de forum: Apache Modul mod_rewirte konfigurieren (german)

Post a comment