|
htaccessサンプル/リダイレクト(サイトの引越し)
実際に動作するリダイレクトのサンプルを掲載しています。 サンプルをご確認のうえ、htaccessファイル作成してください。 当サイトでは、htaccessの作成機能もありますので、是非ご利用ください。
1.サーバー移転などサイト全体のリダイレクト(転送)
サンプルは、「http://htaccess1.cman.jp/sample/redirect/site/」にリンクされています。
実際に開かれるページは、リダイレクトされ
「http://htaccess.cman.jp/sample/redirect/site/」となります。
開かれたページのURLをご確認ください。 |
(1)転送元
(1-1)「.htaccess」ファイルの内容(☆1)
<Files ~ "^\.ht">
deny from all
</Files>
Redirect permanent / http://htaccess.cman.jp
(1-2)「 htaccess1.cman.jp」サーバーのディレクトリ構成
| (1階層目) |
(2階層目) |
| /public_html |
なし |
└.htaccess(前記☆1)
|
|
(2)転送先
(2-1)「.htaccess」ファイルの内容
なし
(2-2)「 htaccess.cman.jp」サーバーのディレクトリ構成
| (1階層目) |
(2階層目) |
(3階層目) |
(4階層目) |
| /public_html |
/sample |
/redirect |
/site |
└.htaccess (共通htaccess) |
└redirect.html (当ページ) |
|
└index.html (転送先となる) |
2.ディレクトリ単位のリダイレクト(転送)
サンプルは、「http://htaccess.cman.jp/sample/redirect/dir1/」にリンクされています。 実際に開かれるページは、リダイレクトされ 「http://htaccess.cman.jp/sample/redirect/dir2/」となります。 開かれたページのURLをご確認ください。 |
(1)「.htaccess」ファイルの内容(☆1)
<Files ~ "^\.ht">
deny from all
</Files>
Redirect permanent /sample/redirect/dir1/ (下記を続けて)
http://htaccess.cman.jp/sample/redirect/dir2/
(2)サーバーのディレクトリ構成
| (1階層目) |
(2階層目) |
(3階層目) |
(4階層目) |
| /public_html |
/sample |
/redirect |
/dir1 |
└.htaccess (共通htaccess) |
└redirect.html (当ページ) |
|
└.htaccess(前記☆1) |
└index.html (転送元となる) |
| /dir2 |
└index.html (転送先となる) |
3.全てトップページへのリダイレクト(転送)
サンプルは、「http://htaccess2.cman.jp/sample/redirect/top/」にリンクされています。 実際に開かれるページは、リダイレクトされ 「http://htaccess.cman.jp/index.html」となります。
開かれたページのURLをご確認ください。 |
(1)転送元
(1-1)「.htaccess」ファイルの内容(☆1)
<Files ~ "^\.ht">
deny from all
</Files>
RedirectMatch 301 .* http://htaccess.cman.jp/index.html
(1-2)「 htaccess2.cman.jp」サーバーのディレクトリ構成
| (1階層目) |
(2階層目) |
| /public_html |
なし |
└.htaccess(前記☆1)
|
|
(2)転送先
(2-1)「.htaccess」ファイルの内容
なし
(2-2)「 htaccess.cman.jp」サーバーのディレクトリ構成
| (1階層目) |
(2階層目) |
(3階層目) |
(4階層目) |
| /public_html |
/sample |
/redirect |
/top |
└.htaccess (共通htaccess) └index.html (転送先となる) |
└redirect.html (当ページ) |
|
└index.html |
サンプルの動作環境
以下の環境でサンプル作成と動作確認を行っています。
| WEBサーバー |
Apache/2.2.3 |
| 動作確認OS |
Windows (XP以降) |
使用環境によってはサンプルが動作しない場合や、サンプル通りにhtaccessファイルを作成しても動作が異なる場合があります。 |