PDA

View Full Version : Need help with specific 301 redirect


Bernard
09-04-2005, 15:49/03:49PM
I've got an existing page called "toc.html" in a subdirectory of my site. I also have the same content in the "index.html" file in the same subdirectory.

Since I don't want duplicate content, I'd like to redirect the "toc.html" page to the index page and delete the toc.html. Could someone please help me out on a proper 301 redirect code for the .htaccess for the subdirectory?

qwerty
09-04-2005, 15:54/03:54PM
It should be something like
redirect 301 /dir/toc.html /dir/

Bernard
09-04-2005, 16:13/04:13PM
Bob, is that code assuming a .htaccess file in the root directory, or the subdirectory itself? Would this be valid for a .htaccess file in the subdirectory:redirect 301 /toc.html /?

qwerty
09-04-2005, 16:27/04:27PM
I suppose so, but to be honest, I've never heard of putting .htaccess anywhere but the root.

Connie
09-04-2005, 17:52/05:52PM
I have .htaccess files in more than one directory. They will take precedent over the .htaccess in the root directory for that folder. I use it for hot link protection of some files only. I think if you try Bernard's suggestion it will work.

qwerty
09-04-2005, 18:01/06:01PM
So under those circumstances, would it recognize that the forward slash refers to the default document of the directory, or would it be necessary to put http://www.domain.com/dir/ instead?

Connie
09-04-2005, 18:22/06:22PM
I would just upload an .htaccess file to that directory with the redirect
301 /toc.html http://www.index.html
and you won't need to point to the root directory. At least that works for hotlinking. I would assume it would work the same way for 301s.

Connie
09-04-2005, 19:28/07:28PM
Bob what I thought would work doesn't . I just tested it. So possibly redirects can only be done from the root directory.

Bernard
09-04-2005, 22:46/10:46PM
I used the following in the subdirectory and it works:redirect 301 /subdirectory/toc.html http://www.domain.com/subdirectory/I could not get it to work without listing the subdirectory as shown.

Connie
09-04-2005, 23:06/11:06PM
Bernard,

Gald you got it to working. I tried several things to day and never could. Thanks for the information.

qwerty
10-04-2005, 08:16/08:16AM
I had noticed in the two or three examples I'd looked at that the target URL was full rather than relative, but I didn't realize that was necessary.

But it does seem odd that what you've got would go in the subdirectory rather than the root. It seems to me that the same line could go in the .htaccess that's in the root (assuming you have one there), and that would mean one less file to deal with.

Bernard
10-04-2005, 11:47/11:47AM
You are probably right about it working from the root and being one less file to deal with, but then, extra code must be parsed/executed for every page request instead of just requests for that section of the site.