views:

136

answers:

3

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

(1) Quite a few of my referrers 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?

A: 

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

markcial
+1  A: 
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.

windyjonas
When you say "recursively", you mean this will work for all subdirectories within the site, I assume?
e100
Yes, exactly. For all subdirectories.
windyjonas
That works great, many thanks. Just to note that I realised I needed to put this rule before my existing Wordpress one.
e100
A: 

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

andrazk
This is not a 301 redirect, depends on the client, and is generally considered bad practice.
e100