PR

サイト移転時の.htaccessサンプル

すべてのリクエストを移転先に無条件に全件転送

ただし、.htaccessだけ残して移転するとレンタルサーバやホスティング業者によってはアカウントが自動削除されることがあるのらしいで注意する。これは転送するだけのサーバーとして利用されるのを防ぐためだと思われる。

スポンサードリンク


# -----------------------------------------------------------------------------
# [ 2009.12.06 ] for coreserver by casey.
# -----------------------------------------------------------------------------
#  - All Access to new URL.
# [ CAUTION ] -----------------------------------------------------------------
#  Even if all transfers ". Htaccess" should not just have to.
#  Be sure the index files must be placed.
#  Otherwise, you will have been removed as an illegal live account.
# -----------------------------------------------------------------------------
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*) http://www.newserver.jp/old/$1 [R=301,L]
</IfModule>
ErrorDocument 404 /moved.html


存在しないファイルやディレクトリにアクセスがあった場合には、新しいサーバーに転送する

静的ドキュメントを順次移転する場合や特定のCGIなどを残しておきたい場合に便利かも。


# -----------------------------------------------------------------------------
# [ 2009.12.07 ] for coreserver by casey.
# -----------------------------------------------------------------------------
#  - dransfer to a new server for all access.
#  - If there is not transfer files and directories.
# [ CAUTION ] -----------------------------------------------------------------
#  Even if all transfers ". Htaccess" should not just have to.
#  Be sure the index files must be placed.
#  Otherwise, you will have been removed as an illegal live account.
# -----------------------------------------------------------------------------
DirectoryIndex moved.html index.html index.htm
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) http://www.newserver.jp/old/$1 [R=301,L]
</IfModule>


moved.htmlサンプル

アクセスがあったときに移転案内を表示するが、METAタグを使ってブラウザに0秒で301リダイレクトさせる。
本当は2秒くらい表示したいところだけど、検索エンジンには0秒転送でないと移転とみなされずSEO的に良くないとか。


<html>
<!-- 2009.12.07 by casey.jp -->
<head>
<META HTTP-EQUIV="REFRESH" CONTENT="0;URL=http://www.newserver.jp/old/">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>移転しました</title>
</head>
<body>
<p align="center">&nbsp;</p>
<p align="center">統合および移転しました</p>
<p align="center">http://www.newserver.jp/old/ </p>
</body>
</html>


コメント