.htaccess DirectoryIndex /subfolder/index.php seems to manage links in a funny way

LLuu picture LLuu · Oct 19, 2015 · Viewed 7k times · Source
  • I have the default myIndex.php in a subfolder of public_html.

  • I added a file .htaccess in public_html.

  • I added DirectoryIndex /subfolder/myIndex.php in it.

myIndex.php contains links and includes. Includes seems to work but links dont: no images and no css but menu.php is included. Links in menu.php dont work either.

If I

  • change .htaccess to DirectoryIndex index.php,

  • create a file index.php in public_html,

  • and put a link to "./subfolder/myIndex.php" in it

    everything works fine.

I dont understand what happens here.

Answer

Olaf Dietsche picture Olaf Dietsche · Oct 20, 2015

DirectoryIndex determines what to do, when a client requests a directory. If you have

DirectoryIndex /subfolder/myIndex.php

then exactly this script will be executed every time the client requests a directory, no matter where this directory is, e.g. /anotherfolder/ or /static/. But when you have

DirectoryIndex index.php

instead, Apache looks for an index.php in the requested directory, e.g. /anotherfolder/index.php or /static/index.php.