Forum Moderators: phranque

Message Too Old, No Replies

subfolder redirect problem /index

/index htaccess redirect problem

         

stein

10:16 am on Aug 28, 2008 (gmt 0)

10+ Year Member



Hi,

Hope someone can help with this I have the following .htaccess in subfolder directory/
RewriteEngine off
RewriteEngine On

redirectMatch permanent ^/directory/?$ http://www.example.com/directory/index.php

requests to http://www.example.com/directory/ are redirected to http://www.example.com/directory/index.php

This is to prevent duplicate content. I must redirect to index.php as the script installed in the directory needs this to function.

However if I type http://www.example.com/directory/index (no.php) this links to the page, all other endings show "404 Not Found"
only ending /index produces this effect.

Why only /index and how can I fix this?

Thanks

[edited by: jdMorgan at 4:09 pm (utc) on Aug. 28, 2008]
[edit reason] Please use "example.com" [/edit]

jdMorgan

4:13 pm on Aug 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your code, by itself, won't affect requests for /directory/index, since that URL does not match your RedirectMatch pattern. So, you've got something else misconfigured.

Also, RedirectMatch is part of mod_alieas, not mod_rewrite, so the RewriteEngine on is not needed. And certainly, there's no reason to precede it with RewriteEngine off in any case.

You're going to need to back up and find out the settings of DirectoryIndex, MultiViews, and (if on Apache 2.x) AcceptPathInfo. All of these can lead to unexpected URL-to-filename mappings, in addition to obvious URL-to-filename translators such as mod_alias and mod_rewrite.

Jim

stein

10:56 am on Aug 29, 2008 (gmt 0)

10+ Year Member



Thank you Jim,

It was the MultiViews, I now have in the subfolder .htaccess

redirectMatch permanent ^/directory/?$ http://www.example.com/directory/index.php

and

Options +FollowSymLinks -multiviews (in the main root .htaccess)

jdMorgan

12:55 pm on Aug 29, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK, be aware that most of the threads we see here are concerned with getting rid of "index.php" in the URL, and simply referring to it as "/". This is the accepted stndard -- For example, you do not type [google.com...] to get to google.

So now the question becomes, "Why do you want to -or think you need to- redirect to index.php?

A more common setup would be to define index.php as your DirectoryIndex, link only to "/", and then redirect requests for index.php back to "/". I strongly suggest that you consider that approach, as it is 'standard' and leaves you free to change your scripting technology with a single change to your configuration file in the future.

Jim