リダイレクト .htaccess

まさはしFPのプロフ画像のダウンロード先変更

/masahashi-info/.htaccess

# Redirect
Redirect permanent /masahashi-info/profile-download/ http://fuji-office.com/masahashi-info2/profile-download/

ps
まさはしFPのブログはデーターベースがいっぱいになり、wordpressの管理画面に入るにはデーターベース内の画像類や記事など削除して容量確保しないと入れないので、新規でmasahashi-info2を設置してそちらで運用中。今回、旧のmasahashi-infoにあるプロフィール画像用の固定ページにある画像を削除したいができないので、その固定ページにアクセスがあったらば現在のプロフィール用固定ページにリダイレクトするように設定。リダイレクト先のページには削除したい画像は無い。

ジェネレーター

https://htaccess.cman.jp/explain/redirect.html

.htaccess wwwに統一

リダイレクト

https://arts-factory.net/rewww/

http→httpsのリダイレクトとwww有無統一リダイレクトを同時に設定する方法

常時SSLを設定している場合は、wwwあり・なしの統一と同時にhttpにアクセスがあった場合httpsにリダイレクトされる設定も設定しておかなければなりません。
httpからhttpsにリダイレクトする方法は以前「httpへのアクセスをhttpsにリダイレクト(転送)させる方法WordPressの対応方法も」という記事で紹介しましたので詳細はそちらで確認していただければと思うのですが。今回はwwwあり・なし統一のリダイレクトとhttp→httpsのリダイレクトを同時に設定する場合の記述方法をご紹介いたします。

wwwありで統一するかつhttpsにリダイレクト設定をする場合

12345RewriteEngine onRewriteCond %{HTTPS} offRewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]RewriteCond %{HTTP_HOST} !^www\. [NC]RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

wwwなしで統一するかつhttpsにリダイレクト設定をする場合

12345RewriteEngine onRewriteCond %{HTTPS} offRewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]RewriteRule ^(.*)$ https://%1%{REQUEST_URI} [R=301,L]

2~3行目がhttpsにリダイレクトする設定になります。4~5行目は先ほど紹介したwww有無を統一する記述になりますが、先ほどとの違いは一点「http://」の部分を「https://」に変更したことです。それ以外に違いはございません。
アドレスを直接入力してwww有無の統一を設定する場合でも同じように「http://」を「https://」に書き換えて設定すれば大丈夫です。

httpのwwwありに統一する方法、wwwなしに統一する方法

wwwありに設定するか、wwwなしに設定するか、どっちがいいという意見はいろいろあるようですが。別にどっちにしても悪いことはないので「好みの方を選択する」でいいと思います。
それでは、wwwありの設定方法とwwwなしの設定方法をご紹介します。

wwwありで統一する場合の設定

123RewriteEngine OnRewriteCond %{HTTP_HOST} !^www\. [NC]RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

wwwなしで統一する場合の設定

123RewriteEngine OnRewriteCond %{HTTP_HOST} ^www\.(.*) [NC]RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,L]

RewriteEngine Onはリダイレクト設定を有効にするための記述で、最初に記述することで機能します。2~3行目がwwwを統一するための記述で、wwwなしに統一する場合はwww付きでアクセスさらたらwwwなしにリダイレクト、wwwありで統一する場合は、wwwなしでアクセスがあった場合wwwを付与してリダイレクトさせる設定がしてあります。

上記のサンプルはいずれも特定のアドレスなどを含まない方法で設定したものなのでそのままコピペで使いまわしができて便利です。

もし、アドレスを直接記述して設定したい場合は次のように設定します。

アドレスを直接記述して設定する場合

使用するドメインが仮に「example.com」だった場合は次のように設定します。

wwwありで統一する場合の設定

123RewriteEngine onRewriteCond %{HTTP_HOST} ^example\.com$RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

wwwなしで統一する場合の設定

123RewriteEngine onRewriteCond %{HTTP_HOST} ^www\.example\.com$RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

2種類の設定方法を紹介しましたが、効果はどちらも同じですので、お好みの方を使用してください。コピペで使用できる方法は便利ですが、サブドメインで使用した場合など、うまく機能しないこともあるようなので、そういった場合は直接アドレスを記述する方法を使たほうがいいです。


https://analyzegear.co.jp/blog/1253

wwwありに統一する

## wwwありに統一する 
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^analyzegear\.co\.jp$
RewriteRule ^(.*)$ https://www.analyzegear.co.jp/$1 [R=301,L]
</IfModule>

wwwなしに統一する

## wwwなしに統一する
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.analyzegear\.co\.jp$
RewriteRule ^(.*)$ https://analyzegear.co.jp/$1 [R=301,L]
</IfModule>

.htacsess リダイレクト サンエツ

サンエツ

この方法で合っているかわからんが、とりあえずリダイレクト設定をした。すでにインデックスされている旧ページで克つ、不要なページは関連する新ページにリダイレクトさせた。茶谷さんがwordpressで作った旧サイトとカートシステムはサーバーからは削除しない事。

/wp
/shop

 

リダイレクト参照ページ

特にこの箇所

ディレクトリ単位のリダイレクト

「old」ディレクトリにアクセスがあった際、「new」ディレクトリに転送をかけたい場合の記述です。

ディレクトリ以下にファイルがある場合は、newでもファイルを置いておかないと404エラーになってしまいます。


RewriteEngine on
RewriteRule ^old(.*)$ /new$1 [L,R=301] 

 

今回の作業のポイント

・httpにアクセスがあってもhttpsにリダイレクト


・茶谷さんが作ったページでインデックスされちゃっているディレクトリを新ページへリダイレクト

・外部サイトのカラミーへのリダイレクト

・茶谷さんが作ったカートシステムの/shop の中にも.htaccessを別個にそれ用として設置
※.htaccessは階層がちがえばたとえ上部階層に.htaccessがあっても同じディレクトリに入っている.htaccessを参照する。

.本当は不要な記述かもしれないけど茶谷さんが作っているwordpressコンテンツに悪さしないようにwordpress関連の.htaccess記述はそのままにする。

編集ファイルは /リダイレクト用/サイトチェンジ後 にある。

ルート直下に.htacess設置↓

AddHandler application/x-httpd-php53 .php

RewriteEngine On

httpsにリダイレクトさせる 。ブリカマはhttpのままだがこの設定でも大丈夫↓
# http->https Redirect 
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# Main RewriteRule for multidomain. httpをhttpsと変更させる
RewriteCond %{HTTP_HOST} ^(sanetsu.com)
RewriteCond %{REQUEST_URI} !^/(sanetsu.com)/
RewriteRule ^(.*)$ https://www.sanetsu.com/$1 [L]

# Redirect 各コンテンツのリダイレクト設定

# Redirect
RewriteRule ^gift(.*)$ /goods$1 [L,R=301]
RewriteRule ^showroom(.*)$ /tenpo$1 [L,R=301]
RewriteRule ^contact(.*)$ /inquiry$1 [L,R=301]
RewriteRule ^policy(.*)$ /privacy$1 [L,R=301]
RewriteRule ^goodslabo/scene(.*)$ /index.html$1 [L,R=301]
RewriteRule ^goodslabo(.*)$ /index.html$1 [L,R=301]
RewriteRule ^online(.*)$ https://sanetsu.shop-pro.jp [L,R=301]
RewriteRule ^category/news(.*)$ /sanetsu-information/category/news$1 [L,R=301]
RewriteRule ^category/blog(.*)$ /sanetsu-information/category/blog$1 [L,R=301]
RewriteRule ^category/press(.*)$ /sanetsu-information/category/press$1 [L,R=301]
RewriteRule ^category/giftitem/gift(.*)$ /sanetsu-information/category/giftitem/gift$1 [L,R=301]
RewriteRule ^shop(.*)$ https://sanetsu.shop-pro.jp [R=301,L]
RewriteRule ^goodsitem(.*)$ /index.html$1 [L,R=301]
RewriteRule ^giftitem(.*)$ /index.html$1 [L,R=301]
RewriteRule ^news(.*)$ /sanetsu-information/category/news$1 [L,R=301]

ErrorDocument 404 https://www.sanetsu.com

# Main RewriteRule for multidomain. ブリカマはSSLしないのでそのまま変更なし↓
RewriteCond %{HTTP_HOST} ^(www.burikama.com)
RewriteCond %{REQUEST_URI} !^/(www.burikama.com)/
RewriteRule ^(.*)$ /%{HTTP_HOST}/$1/ [L]

# Main RewriteRule for multidomain.
RewriteCond %{HTTP_HOST} ^(burikama.com)
RewriteCond %{REQUEST_URI} !^/(burikama.com)/
RewriteRule ^(.*)$ http://www.burikama.com/$1 [L]

# 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

 

shop (茶谷さんカート)下に.htaccess設置↓

RewriteEngine On

RewriteRule gift.php$ https://www.sanetsu.com/goods/index.html
RewriteRule ^(.*)$ https://sanetsu.shop-pro.jp/

[R=301,L]

 

 

 

旧ページのいらない物をgoogleインデックスから削除するためにインデックス削除申請。

 

 

 

不要なページをクローラーされないようにrobots.txtをアップ

User-agent:*
Disallow: /giftlabo/
Disallow: /shop/
Disallow: /wp/
Disallow: /giftitem/
Disallow: /goodsitem/

 

リダイレクト .htaccess

https://ferret-plus.com/2186

 

.ページ単位のリダイレクト

「old.html」にアクセスがあった際に「http://www.example.com/new.html」へ301リダイレクトさせる記述です。


RewriteEngine on
RewriteRule ^old.html$ http://www.example.com/new.html [L,R=301] 

Lは「この処理はここで終わり(LAST)」の意味で、R=301は「301リダイレクトをしなさい」という指定になります。

ちなみに、Rだけだと302リダイレクトになるので、301リダイレクトを行いたい場合は必ずR=301の指定をするようにしてください。

2-2.ディレクトリ単位のリダイレクト サンエツ↓

「old」ディレクトリにアクセスがあった際、「new」ディレクトリに転送をかけたい場合の記述です。

ディレクトリ以下にファイルがある場合は、newでもファイルを置いておかないと404エラーになってしまいます。


RewriteEngine on
RewriteRule ^old(.*)$ /new$1 [L,R=301] 

2-3.http→https のリダイレクト

HTTPアクセスされたページをSSLでリダイレクトをする方法です。SSLを使いたいディレクトリに以下を記述したファイルを入りします。

GoogleがSSL化を推奨していることもあり、SSL対応を行う人も増えていますが、この場合もHTTPでのアクセスをHTTPSにリダイレクトしたほうが良いです。


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

 

 

 

 

 

 

 

https://www.itti.jp/web-design/htaccess-redirect/

 

URLが大幅に変わる

ドメイン、ディレクトリ、ページ全てが変わる場合は下記になります。

.htaccess

RewriteEngine on
RewriteRule https://www.old.com/old/old.html https://www.new.com/new/new.html [R=301,L]

//下記の方法でも可能
RewirteEngine on
Redirect permanent https://www.old.com/old/old.html https://www.new.com/new/new.html

 

https://sem-journal.com/seo/how-to-redirect/

 

ジェネレーター

https://htaccess.cman.jp/explain/redirect.html

 

リダイレクト NOT FUND404 の時の方法 センティアサイト .htaccess

※404は使わずに301を使うようにと指導されたので下記の方法は使わない。301の方法を用いる。下記

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.yoga-union.jp [R=301,L]

 

一応404対応したいなら下記。

 

 

https://allabout.co.jp/gm/gc/23770/2/

センティアで実施

  1. 移転案内を掲載したページを1つ用意 (moveinfo.htmlなど)
  2. 「404 Not Found」エラーの際にはそのページが表示されるよう.htaccessを記述
  3. サイト内の全ページを削除 (※一部だけを移転するなら、移転する分だけを削除)

上記のようにすると、(全ページが削除されているため)サイト内のどのURLにアクセスしても「404 Not Found」エラーが表示されるようになります。その「404 Not Found」エラーが「移転案内」になっているので、結果として、「サイト内のどのURLにアクセスしても移転案内が表示される」ことになります。

具体的な作業手順は以下の通りです。

1. 移転案内を掲載したページを1つ用意 (moveinfo.htmlなど)
例えば「moveinfo.html」などのファイル名で、移転案内を掲載したページを用意します。このファイルは、ウェブサイト内の最上階層(トップページがあるディレクトリ)にアップロードしておきます。

2. 「404 Not Found」エラーの際にはそのページが表示されるよう.htaccessを記述
「.htaccess」ファイルに、以下の1行を記述します。これは、404エラーが発生した際には最上階層にある「moveinfo.html」を表示させるようにする記述です。

ErrorDocument 404 /moveinfo.html

※「/moveinfo.html」の部分は、先ほど作成したファイル名を指定します。何でも好きな名称で構いません。先頭の「/」記号を忘れないよう注意して下さい。なお、最上階層以外のディレクトリ(フォルダ)に置いた場合は、ディレクトリ名も加える必要があります。ここでは絶対パスで記述する必要があり、相対パスで書いてはいけません。

3. 404エラーの表示確認
存在しないページをブラウザで表示させてみて下さい。そこで、通常の「404 Not Found」エラーメッセージではなく、移転案内を書いた独自ページ(moveinfo.html)が表示されればOKです。表示されない場合は、記事「Not Foundなど エラーメッセージを独自作成」の5ページ目にある「うまくいかない場合の原因と解決方法」をご参照下さい。

4. 全ページを削除
最後に、ウェブサーバ上にあるすべてのHTMLファイルを削除します。これによって、どのページにアクセスしようとしても「404 Not Found」エラーが出るようになります。つまり、どのページにアクセスしても、同じ移転案内が表示されるわけです。

自動移動機能を加えるには
上記の方法だと、全ページに一括して移転メッセージを表示できますが、その後の自動転送は行われません。メッセージを表示した後に自動転送を行いたい場合は、次のページ以降でご紹介する、HTMLやJavaScriptを使って自動転送する方法と組み合わせて下さい。

※次のページでご紹介する「HTMLのmeta要素を使う方法」だと、パス名(URLの構造)を維持した状態での移動ができません。パスを維持して転送したい場合は、最後のページでご紹介する「JavaScriptを使って自動転送する方法」と組み合わせて下さい。

それでは次に、HTMLのmeta要素を使って自動移動(リダイレクト)する方法をご紹介いたします。

 

センティアで実施

● /.htaccess  に下記表記

ErrorDocument 404 /move.html

 

●リダイレクト用のファイルとindex.htmlに下記表記してルート下に設置

(index.htmlにも記さないとhttp://centia.jpでアクセスされるとnot fundになるから)

<!doctype html>
<html>
<head>
<meta charset=”utf-8″>
<title>ページ移設</title>
<style type=”text/css”>
h2 {
text-align: center;
margin-top: 100px;
}
</style>

<!–リダイレクト–>
<meta http-equiv=”refresh” content=”2;URL=https://centia.jp/”>

</head>

<body>

<h2>インドアテニスククール センティアのwebサイトは移転いたしました。</h2>
<h2> 自動で新サイトへ移ります。 </h2>
</body>
</html>

 

スマホ モバイル 振り分け

<!–モバイルからのアクセスの時–>
<script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js”></script>
<script type=”text/javascript”>
$(function(){
var agent = navigator.userAgent;
var redirectPass = ‘/index3.html’;
if(agent.search(/iPhone/) != -1 || agent.search(/iPad/) != -1 || agent.search(/iPod/) != -1 || agent.search(/Android/) != -1){
location.href = redirectPass;
}
});
</script>

 

※上記の設定だとリダイレクト先はドメイン直下のindex3.html。
テストサイトのcm-creation.net/index3.htmlはないからnot foundするので、テスト確認時はコメントアウトしておく。本サイトではドメイン直下にindex3.htmlあれば大丈夫。

ギャラリーサク&next door サイトクローズ

サイトクローズ準備の為に、サイトにアクセスしたらクローズのお知らせページへリダイレクト設定をした。

●ギャラリーサク リダイレクト

<Files ~ \”^.(htaccess|htpasswd)$\”>
deny from all
</Files>

Redirect permanent /index.html http://gallery-saku.jp/close.html
Redirect permanent /cafe/event/index.html http://gallery-saku.jp/close.html
Redirect permanent /cafe/menu/index.html http://gallery-saku.jp/close.html
Redirect permanent /cafe/paticular/index.html http://gallery-saku.jp/close.html
Redirect permanent /cafe/recomendation/index.html http://gallery-saku.jp/close.html
Redirect permanent /gallery/example/index.html http://gallery-saku.jp/close.html
Redirect permanent /gallery/new/index.html http://gallery-saku.jp/close.html
Redirect permanent /gallery/process/index.html http://gallery-saku.jp/close.html
Redirect permanent /gallery/product/wind/index.html http://gallery-saku.jp/close.html
Redirect permanent /gallery/product/taste/index.html http://gallery-saku.jp/close.html
Redirect permanent /gallery/product/attraction/index.html http://gallery-saku.jp/close.html
Redirect permanent /gallery/product/light/index.html http://gallery-saku.jp/close.html
Redirect permanent /info/index.html http://gallery-saku.jp/close.html
Redirect permanent /inquiry/index.html http://gallery-saku.jp/close.html
Redirect permanent /nousaku/index.html http://gallery-saku.jp/close.html
Redirect permanent /plus1/index.html http://gallery-saku.jp/close.html
Redirect permanent /privacy/index.html http://gallery-saku.jp/close.html
Redirect permanent /saku_blog/ http://gallery-saku.jp/close.html

order deny,allow

 

 

●ネクストドア リダイレクト

<Files ~ \”^.(htaccess|htpasswd)$\”>
deny from all
</Files>

Redirect permanent /index.html http://nextdoor2010.jp/close.html
order deny,allow

301リダイレクト(同一ドメイン内)の設定方法:「.htaccess」の書き方

http://yakugakusuikun.com/9805.html

 

リダイレクト生成ツール

 

<Files ~ \”^.(htaccess|htpasswd)$\”>
deny from all
</Files>

Redirect permanent /index.html http://gallery-saku.jp/close.html
Redirect permanent /cafe/event/index.html http://gallery-saku.jp/close.html
Redirect permanent /cafe/menu/index.html http://gallery-saku.jp/close.html
Redirect permanent /cafe/paticular/index.html http://gallery-saku.jp/close.html
Redirect permanent /cafe/recomendation/index.html http://gallery-saku.jp/close.html
Redirect permanent /gallery/example/index.html http://gallery-saku.jp/close.html
Redirect permanent /gallery/new/index.html http://gallery-saku.jp/close.html
Redirect permanent /gallery/process/index.html http://gallery-saku.jp/close.html
Redirect permanent /gallery/product/wind/index.html http://gallery-saku.jp/close.html
Redirect permanent /gallery/product/taste/index.html http://gallery-saku.jp/close.html
Redirect permanent /gallery/product/attraction/index.html http://gallery-saku.jp/close.html
Redirect permanent /gallery/product/light/index.html http://gallery-saku.jp/close.html
Redirect permanent /info/index.html http://gallery-saku.jp/close.html
Redirect permanent /inquiry/index.html http://gallery-saku.jp/close.html
Redirect permanent /nousaku/index.html http://gallery-saku.jp/close.html
Redirect permanent /plus1/index.html http://gallery-saku.jp/close.html
Redirect permanent /privacy/index.html http://gallery-saku.jp/close.html
order deny,allow