开发者

How do I do this simple 301 redirect from index.htm to root?

I've read various reference sites on redirection, and to be honest I understand very little.

I currently have standard WordPress mod_rewrite redirect rules in my .htaccess:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Quite a few of my refer开发者_JAVA百科rers go to a old URL http://www.example.com/index.htm, which gives them an error, and I want them to be seamlessly redirected to http://www.example.com/. I believe a 301 redirect is the best method for this.

What do I need to do?


RewriteEngine On
RewriteCond %{THE_REQUEST} /index\.html? [NC]
RewriteRule ^(.*/)?index\.html?$ /$1 [R=301,L]

This will translate all occurrences of index.html or index.htm to just the directory, recursively.


I'm not 100% sure but i guess that should be RewriteRule ^index.htm$ / [R=301] or something like this


Create an index.html, containing the code:

<HTML>
<HEAD>
<META HTTP-EQUIV="refresh" CONTENT="seconds;URL=the-other-url">
</HEAD>
<BODY>
You will be redirected...
</BODY>
</HTML> 

Where "seconds" is the duration of the delay (in seconds) before the redirection. Set a "0" for instant redirect.

"the-other-url" is http://www.example.com/index.php

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜