WordPressでindex.htmlをリダイレクトする方法

既存のサイトをWordPressに置き換えたあとによく発生する問題です。
リンクや検索エンジンの登録が、”/”ルートではなく ”/index.html”に対してなされている場合があります。
このとき、WordPressは404を返してしまうんですね。

.htaccessでリダイレクト処理

じゃあ、ってんで.htaccessに単純に

Redirect permanent /index.html /

と追加すると、リダイレクトが無限ループしてしまいます。

ここは、mod_rewriteで次のように書き換えるのが正解。

<ifmodule mod_rewrite.c="">
       RewriteEngine on
       RewriteCond %{THE_REQUEST} ^.*/index.html
       RewriteRule ^(.*)index.html$ /$1 [R=301,L]
</ifmodule>

あるいはシンプルにこれでもいけるようです。

RedirectMatch 301 ^/index\.htm.$ /

index.htm.で、index.htmlとindex.htmとどちらでも対応できるようになっている。はず。

広告

プラグインRedirectionを使う

もう一つの方法。
WordPressのリダイレクトを管理するプラグイン、Redirectionを使います。
WordPress › Redirection « WordPress Plugins
リダイレクトのマッチ回数がカウントされるので便利ではありますが、WordPressのバージョンに問題がある場合、データベース容量に制約がある場合は使わない方が無難です。
(リダイレクトのログがどんどん溜まっていきます)

About: dacelo


44 thoughts on “WordPressでindex.htmlをリダイレクトする方法”

  1. Pingback: MOON1969
  2. wonderful publish, very informative. I’m wondering why the
    opposite experts of this sector don’t understand this. You should continue your writing.

    I am confident, you’ve a great readers’ base already!

  3. Fascinating blog! Is your theme custom made or did you download it from somewhere?

    A theme like yours with a few simple adjustements would really make my blog stand
    out. Please let me know where you got your theme. Appreciate it

  4. It’s awesome to go to see this web site and reading the views of all friends on the topic of this article, while I am also keen of getting familiarity.

  5. Yesterday, while I was at work, my cousin stole my iphone and tested to see if it
    can survive a twenty five foot drop, just so she can be a youtube
    sensation. My apple ipad is now broken and she has 83 views.
    I know this is totally off topic but I had to share it with someone!

  6. It’s perfect time to make some plans for the future and it is
    time to be happy. I’ve read this post and if I could I wish to suggest you
    few interesting things or tips. Perhaps you could write next
    articles referring to this article. I wish to read more things about it!

  7. Having read this I thought it was extremely enlightening.

    I appreciate you spending some time and effort
    to put this information together. I once again find myself spending
    a significant amount of time both reading and leaving comments.
    But so what, it was still worth it!

  8. Hey there, I think your blog might be having browser compatibility issues.
    When I look at your blog in Chrome, it looks
    fine but when opening in Internet Explorer, it has some overlapping.
    I just wanted to give you a quick heads up! Other then that, superb blog!

  9. Great blog! Do you have any recommendations for aspiring writers?
    I’m hoping to start my own blog soon but I’m a little lost on everything.
    Would you propose starting with a free platform like WordPress or go for a paid option? There
    are so many choices out there that I’m totally confused ..
    Any tips? Bless you!

  10. I’m extremely pleased to uncover this website. I wanted
    to thank you for ones time for this particularly fantastic read!!
    I definitely loved every bit of it and i also have you bookmarked to look at new stuff in your site.

  11. Today, I went to the beachfront with my children. I found a sea shell
    and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and screamed.
    There was a hermit crab inside and it pinched her ear.
    She never wants to go back! LoL I know this is completely off topic but I had to tell someone!

    1. Your style is very unique compared to other people I have read stuff from.
      Many thanks for posting when you have the opportunity, Guess I will just book mark
      this site.

  12. Have you ever thought about adding a little bit more than just your articles?
    I mean, what you say is valuable and everything. Nevertheless think about if you added
    some great photos or videos to give your posts
    more, “pop”! Your content is excellent but with images and
    videos, this website could certainly be one of the best in its field.

    Good blog!

Leave a Reply

Your email address will not be published. Required fields are marked *