memo.xight.org

日々のメモ

リダイレクトの問題

  mod_rewriteを利用する場合
# For sites running on a port other than 80
RewriteCond %{HTTP_HOST}   !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/(.*)         http://www.example.com:%{SERVER_PORT}/$1 [L,R]
# And for a site running on port 80
RewriteCond %{HTTP_HOST}   !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         http://www.example.com/$1 [L,R]


RewriteEngine on
RewriteCond %{HTTP_HOST} ^(example\.lolipop\.jp|www\.example\.com)(:80)?
RewriteRule ^(.*) http://example.com/$1 [R,L]"


name-based virtual hosting

NameVirtualHost *

<VirtualHost *>
  ServerName www.example.net
  ServerAlias example.com
  Redirect permanent / http://www.example.com/
</VirtualHost>

<VirtualHost *>
  ServerName www.example.com
  DocumentRoot /usr/local/apache/htdocs
</VirtualHost>


Reference

Apache Server Frequently Asked Questions - Configuration Questions - My site is accessible under many different hostnames; how do I redirect clients so that they see only a single name?
http://www.apache.jp/docs/misc/FAQ.html#canonical-hostnames
独自ドメイン運営助け合い掲示板 - サブドメインのアドレスを
http://lolipoking.lolipop.jp/domain/patio.cgi?mode=view&no=4