相忘于江湖

泉涸,鱼相与处于陆,相呴以湿,相濡以沫,不如相忘于江湖。《庄子.大宗师篇》

Force Canonical Hostnames in Web Server

Thursday Jul 05, 2007

People like to use the short hostnames to access a web server, eg, http://agc163/ or http://agc163.prc/. It would be better that apache (httpd) can re-direct this request to a canonical hostname, thus we can force the use of canonical hostnames. Code snippet in httpd.conf:


RewriteEngine on
Options +FollowSymLinks
RewriteCond %{HTTP_HOST}   !^agc163\.prc\.sun\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http://agc163.prc.sun.com/$1 [L,R]

 Reference: http://httpd.apache.org/docs/1.3/misc/rewriteguide.html

[6] Comments
Like this post? del.icio.us | furl | slashdot | technorati | digg