ここでは.htaccessでwwwやindex.html、index.phpを統一する方法を解説していきます。

wwwをなしに統一
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteRule (.*) http://example.com/$1 [R=301,L]
wwwをありに統一
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
index.htmlをなしに統一
RewriteEngine On
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://example.com/$1 [R=301,L]
index.phpの場合はindex.htmlの箇所をindex.phpに置き換えてください。
CakePHPでURLの統一
/app/webroot/.htaccess
<ifmodule mod_rewrite.c="">
RewriteEngine On
# wwwなしに統一
RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteRule (.*) http://example.com/$1 [R=301,L]
# /indexなしに統一
RewriteCond %{THE_REQUEST} ^.*/index
RewriteRule ^(.*)index/$ http://example.com/$1 [R=301,L]
# 以下はCakePHPのまま編集しない
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</ifmodule>
なかなか変更されない場合はブラウザのCookieやキャッシュを削除してから確認してください。
