0

I'm working on a PHP project using Apache 2.2.22 and PHP 5.3.10 and I'm running into an issue where index and index.php are being treated as the same file.

I have an admin/index.php that redirects to admin/index to allow my mod_rewrite rules in .htaccess to take over and reroute the request into a custom framework. The problem is, when the browser goes to admin/index it goes into an infinite redirect loop because the request is being sent to admin/index.php which redirects to admin/index

I've tried removing the htaccess file to see if there was a problem with my mod_rewrite rules that was causing it and it didn't change anything. It just redirects to admin/index endlessly.

I've never heard of this behavior before, skimming over some Google results and skimming through the apache configuration files didn't show anything really obvious. Has anyone seen this before and know how to fix it?

EDIT: Below is the code being used by the index.php to redirect to index.

<?php
    header("Location: index");
    die();
5
  • Are you saying you have an index.php and a directory called index? Commented Jun 26, 2012 at 22:08
  • this could be related, but I'm also curious about your DirectoryIndex setting... Commented Jun 26, 2012 at 22:09
  • It's not default behavior in Apache or PHP so I suspect there is another set of rewrite rules or redirects set up elsewhere, maybe in httpd.conf or the httpd-vhosts.conf file? Or you may have a .htaccess file in a parent directory that is still taking precedence over the one you removed which didn't solve the problem. Commented Jun 26, 2012 at 22:12
  • Post your php redirect code please. I've seen something similar if the redirect to a directory does not contain the final forward-slash. Commented Jun 26, 2012 at 22:14
  • There is not a directory called index in admin/ and I'm using the stock configuration settings from Ubuntu's package with the only modification being a change to the document root. Commented Jun 27, 2012 at 13:43

2 Answers 2

1

This may be due to MultiViews being enabled:

The effect of MultiViews is as follows: if the server receives a request for /some/dir/foo, if /some/dir has MultiViews enabled, and /some/dir/foo does not exist, then the server reads the directory looking for files named foo.*, and effectively fakes up a type map which names all those files, assigning them the same media types and content-encodings it would have if the client had asked for one of them by name. It then chooses the best match to the client's requirements.

https://httpd.apache.org/docs/2.2/content-negotiation.html#multiviews

Try adding Options -MultiViews to your .htaccess

Sign up to request clarification or add additional context in comments.

Comments

0

Enable rewrite Logging inside Apache and raise the log level. That way apache will tell you exactly, step by step, what request is rewritten how, in which order and why.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.