Forum Moderators: phranque

Message Too Old, No Replies

Redirect /folder/index.html to /folder/

         

madmatt69

6:47 pm on Mar 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hey all,

I've got a page at /folder/ that everyone links to. The problem is they don't link to the /folder/index.html.

And google indexes both..Possible dupe content issue!

So I tried doing a standard 301:
redirect 301 /folder/index.html [mysite.com...]

And I get an error saying that it's in an infinite loop.

Is there another way to do this?

jdMorgan

8:27 pm on Mar 6, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, you told it to loop, because your match URL-path and your 'new' URL are the same.

You could do this with:


RedirectMatch 301 ^/folder/$ http://www.example.com/folder/index.html

However, linking to "index.whatever" looks kind of amateurish, and most sites are set up to link to just "/" for directory indexes. It's shorter and looks better in search results as well. And that is why people linking to you omit the "index.html". Should you decide to adopt the standard approach, you can canonicalize all directory index requests by redirecting in the opposite direction like this:

DirectoryIndex index.html
#
# Redirect all <subdirectory>/index.html requests to <subdirectory>/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*/index\.html\ HTTP/
RewriteRule ^(([^/]+/)*)index\.html$ http://www.example.com/$1 [R=301,L]

Jim

[edited by: jdMorgan at 8:28 pm (utc) on Mar. 6, 2007]

madmatt69

1:03 am on Mar 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks as always.

The actual file extension is .php, so I changed all the .html reference in your code to .php.

And, sadly, it didn't work. Nothing changed. I checked the headers too, and they just return 200 on the index.php file.

Is there another option? Or maybe something different that needs to be done if applying it to a .php?

coopster

1:06 am on Mar 7, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I'm guessing here, but it may be MultiViews. If you aren't using MultiViews, turn them off.
Options -MultiViews

madmatt69

1:28 am on Mar 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



THanks for the input.

I tried:
Options -MultiViews

DirectoryIndex index.php
#
# Redirect all <subdirectory>/index.html requests to <subdirectory>/
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*/index\.php\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://www.example.com/$1 [R=301,L]

And it still doesn't seem to change anything. Headers still remain the same.

Plan C? :)

coopster

1:30 am on Mar 7, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Clear your browser's cache too.

jdMorgan

1:41 am on Mar 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just to clarify, do you have any other working RewriteRules? If not, you will need to add

Options +FollowSymLinks -MultiViews
RewriteEngine on

ahead of your mod_rewrite code.

Jim

madmatt69

2:12 am on Mar 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have this:

Options +FollowSymlinks -Indexes

Should I add the -Multiviews?

coopster

5:56 am on Mar 8, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



If you haven't tried it yet, then yes, just to be certain.