MENU

.htaccessの使い方まとめ|https統一、wwwのありなし統一など

目次

httpsに統一

RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

wwwのありなしの統一

<!– wwwありに統一 –>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.jp$
RewriteRule ^(.*)$ http://www.domain.jp/$1 [R=301,L]

<!– wwwなしに統一 –>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.domain\.jp$
RewriteRule ^(.*)$ http://domain.jp/$1 [R=301,L]

index.html(php)をなしで統一

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} ^.*/index.(html|php)
RewriteRule ^(.*)index.(html|php)$ http://%{HTTP_HOST}/$1 [R=301,L]

まとめの記述

よく使う設定
www:無し
index.html:表示しない
httpsに統一

Options +FollowSymLinks
RewriteEngine on

<!– wwwなしに統一 –>
RewriteCond %{HTTP_HOST} ^www\.domain\.jp$
RewriteRule ^(.*)$ http://domain.jp/$1 [R=301,L]

<!– index.html(php)なしで統一 –>
RewriteCond %{THE_REQUEST} ^.*/index.(html|php)
RewriteRule ^(.*)index.(html|php)$ http://%{HTTP_HOST}/$1 [R=301,L]

<!– httpsに統一 –>
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!

この記事を書いた人

目次