memo.xight.org

日々のメモ

mod_rewrite で Canonical Hostnames

xxx.example.com から www.example.comへのリダイレクト方法の例

RewriteCond %{HTTP_HOST}   !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http://www.example.com/$1 [L,R=301]


xxx.example.com から example.comへのリダイレクト方法の例

RewriteCond %{HTTP_HOST}   !^example\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http://example.com/$1 [L,R=301]


Reference

Apache module mod_rewrite
http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html

Apache URL Rewriting Guide
http://httpd.apache.org/docs/1.3/misc/rewriteguide.html

Apache URL Rewriting Guide (和訳)
http://japache.infoscience.co.jp/rewriteguide/