ブログ移行におけるリダイレクト
このブログは別のブログから一部を引越ししてきたのだが、その際に.htaccessでリダイレクトの設定
をしておいたのでメモ。
元のブログでは”open-source”という親カテゴリに子カテゴリを作っていたが、ここでは親カテゴリ
はいらないなと思ったので、元ブログの.htaccessに以下のように書いておいた。
RedirectMatch (.*)open-source/linux/(.*)$ http://open-groove.net/linux/$2
RedirectMatch (.*)open-source/mysql/(.*)$ http://open-groove.net/mysql/$2
RedirectMatch (.*)open-source/apache/(.*)$ http://open-groove.net/apache/$2
RedirectMatch (.*)open-source/lpic/(.*)$ http://open-groove.net/lpic/$2
RedirectMatch (.*)open-source/tomcat/(.*)$ http://open-groove.net/tomcat/$2
:
:
上記をmod_rewrite.cディレクティブコンテナに記述。とりあえず機能してくれているようだ。
ついでにBaiduスパイダー(百度クローラー)対策についても書いておく。
ここに書くまでもなくいろんな所で書かれている話だが、Baiduスパイダーとサヨナラするには
robots.txtで拒否するだけでは駄目である。そこで、.htaccessに以下を記述している。
<Files robots.txt>
Allow from all
</Files>
SetEnvIf User-Agent “Baiduspider” deny_agent
SetEnvIf User-Agent “Baiduspider+” deny_agent
SetEnvIf User-Agent “BaiduImagespider” deny_agent
order allow,deny
allow from all
deny from env=deny_agent
まず「robots.txtだけは誰でも読ませる」という設定にしておく。.htaccessで全て拒否、
つまりrobots.txtを読ませない設定だと、Baiduスパイダーは「robots.txt読めないからとりあえず
全部アクセスしてみるよ!」と勝手に判断するらしいので、、、
robots.txtの中身は以下。
User-agent: baiduspider
Disallow: /
User-agent: baiduspider+
Disallow: /
User-agent: baiduimagespider
Disallow: /
ブログ引越しの全体的な手順については、次回にでも。
追記
RedirectMatchはmod_rewrite.cコンテナ外に記述、がきっと正しい。実際それで動いているし。。
それと、「引越し」を示す「Permanent」か「301」を書いておいた方がよいらしいので、追記しておいた。
RedirectMatch 301 (.*)open-source/tomcat/(.*)$ http://open-groove.net
何も書かないと、デフォルトの「302」(ただの転送)扱いになるとのこと。