静的ウェブサイトをWordPress でリニューアルするに当たり、今まで使っていたトップページであるindex.htmlをWordPress版新サイトのトップページ(index.php)へリダイレクトさせる方法のご紹介です。
.htaccessを編集してindex.htmlをindex.phpへリダイレクト
WordPress の管理画面からパーマリンクを更新すると、サーバー上に以下のような.htaccessファイルが生成されると思いますが| 
					 1 2 3 4 5 6 7 8 9 10 11  | 
						# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress  | 
					
これをベースに、index.htmlをindex.phpへリダイレクトさせる記述を足します。
| 
					 1 2 3 4 5 6 7 8 9 10 11 12  | 
						# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.html?$ / [R=301,L] RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress  | 
					
上記ソース5行目RewriteRule ^index\.html?$ / [R=301,L]が今回追加した記述です。
参考ページ
index.htmlにアクセスした際にindex.phpにリダイレクトする方法
  
  
  
  

コメント