Blog

【htaccess】リダイレクトいろいろ

2017/04/22

htaccess

備忘録です。

htaccessによるリダイレクト方法いろいろです。

参考サイト
01リダイレクトとは〜htaccessを利用して転送を行う方法
.htaccessで旧ドメインを新ドメインにリダイレクトさせる設定

旧ドメインを新ドメインへリダイレクト

新ドメインのみ記述

RewriteEngine On
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
旧ドメインを新ドメインへリダイレクト

旧ドメインと新ドメインを記述

www.ikuwow.mydns.jpをwww.ikuwow.comにリダイレクト
ikuwow.comをwww.ikuwow.comにリダイレクト

RewriteEngine On
RewriteCond %{http_host} ^www.ikuwow.mydns.jp
RewriteRule ^(.*) http://www.ikuwow.com/$1 [R=301,L]
 
RewriteCond %{http_host} ^ikuwow.com
RewriteRule ^(.*) http://www.ikuwow.com/$1 [R=301,L]
ページ単位のリダイレクト
RewriteEngine on
RewriteRule ^old.html$ http://www.example.com/new.html [L,R=301] 
ディレクトリ単位のリダイレクト
RewriteEngine on
RewriteRule ^old(.*)$ /new$1 [L,R=301] 
http→httpsのリダイレクト
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
SSLでリダイレクトするページを個別で指定する場合
RewriteEngine on

RewriteCond %{REQUEST_URI} .*/a.html$ [OR]
RewriteCond %{REQUEST_URI} .*/b.html$
RewriteCond %{ HTTP S} off
RewriteRule ^(.*)$ https://%{ HTTP _HOST}%{REQUEST_URI} [L,R=301]
 
RewriteCond %{REQUEST_URI} !(.*/a.html$)
RewriteCond %{REQUEST_URI} !(.*/b.html$)
RewriteCond %{ HTTP S} on
RewriteRule ^(.*)$ http://%{ HTTP _HOST}%{REQUEST_URI} [L,R=301]
https→httpのリダイレクト
RewriteEngine on
RewriteCond %{ HTTP S} on
RewriteRule ^(.*)$ http://%{ HTTP _HOST}%{REQUEST_URI} [L,R=301]
wwwなしURLをwwwありURLへリダイレクトする記述
RewriteEngine on
RewriteCond %{ HTTP _HOST} ^example\.com
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
wwwありURLをwwwなしURLへリダイレクトする記述
RewriteEngine on
RewriteCond %{ HTTP _HOST} ^www.example\.com
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301] 
TOPページのindex.htmlをindex.html無しに統一する記述
RewriteEngine on
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://example.com/$1 [L,R=301] 

カテゴリー

月間アーカイブ

MORE

ミュージシャンズ・プラザ

神社仏閣ホームーページ制作

ホームページ制作問合せ