We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 6369
    • 18 Posts
    What happens if there is a index.php and a index.html file in the root directory at the same time?
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      That depends on your server’s configuration; the directive is DirectoryIndex and it takes a list of files and will apply them in order.

      http://httpd.apache.org/docs/1.3/mod/mod_dir.html
      http://www.boutell.com/newfaq/creating/directoryindex.html (for IIS)
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 25663 MODX Staff
        • 12,272 Posts
        Jason swears that that particular scenario leads to a black hole opening up and swallowing all the Intrawebs. Or maybe not. tongue
          Ryan Thrash, MODX Co-Founder
          Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Maybe the black hole just swallows up Al Gore?
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 9207 ☆ A M B ☆
            • 2,475 Posts
            Default Apache config will look for the index.html before the index.php, but as Susan said, it depends on your server config. Your host may not use the default configuration for that.
              • 14877
              • 110 Posts
              That’s interesting. Learn something new every day! I had always been under the impression that it was the browser that determined the search order and thus, for example:

              http://www.somewhere.com/ was slower than
              http://www.somewhere.com/index.php

              because there was a back-and-forth between the browser (trying various index.somethings, welcome.somethings, etc.) and the web server.

              Of course, the downside to having bookmarks that explicitly say "index.php" (or whatever) is that if the site changes, you get a "Page not found" message.

              One of the things I had tried in the past, was to have an index.html file stored in a sub-directory. I then temporarily moved (or copied) it to the web root directory when I was doing maintenance on the site. I changed that to swap the two files instead, because of people still getting into the site (they had index.php specified explicitly).

              I suppose the obvious answer is for me to create a "down for maintenance" version of index.php and swap the two index.php files grin
                __________________
                JRG
                • 14877
                • 110 Posts
                Quote from: daleylife at Jan 17, 2011, 02:36 PM

                I suppose you would confuse the server if you had more than 1 index.php or index.html? ha ha!!

                Only if they are in the same directory wink

                It would probably use the youngest... shocked Maybe the younger version of index.php should be called index.php-jr ?
                  __________________
                  JRG
                  • 9207 ☆ A M B ☆
                  • 2,475 Posts
                  I don’t think you can have more than one version of the index.php file... the Apache configuration explicitly lists the files that should fulfill the indexing function in its DirectoryIndex directive. This is how some sites use a "default.html" instead of the more common "index.html"

                  For example:

                  DirectoryIndex index.html index.php index2.html


                  In that example, if you had an index.php and an index2.html both in the same directory, and you navigated to that directory, e.g. www.yoursite.com/yourdir/, then Apache would serve up the index.php page because it’s defined first in the DirectoryIndex directive. If you deleted the index.php, then the page request would cause Apache to serve up the index2.html. If you put in an index.html in that directory, then the same request would bring up index.html because it has priority.

                  www.yoursite.com/index.html is technically a bit faster because you are explicitly asking for a certain file, whereas www.yoursite.com/ is relying on Apache to calculate which file should be returned. In that same vein, www.yoursite.com/somedir is slightly slower than www.yoursite.com/somedir/ because the trailing slash explicitly says that you’re requesting a directory, whereas if you omit that trailing slash, Apache has to figure out whether you are requesting a file or a directory, then once it figures out that you’re requesting a directory, it has to scan the directory for a valid DirectoryIndex.

                  Make sense?
                    • 14877
                    • 110 Posts
                    Is DirectoryIndex one of those directives one can put in .htaccess ?
                      __________________
                      JRG
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      Possibly; it depends on the server configuration whether or not it allows that.

                      http://www.htaccess-guide.com/directoryindex-uses/
                        Studying MODX in the desert - http://sottwell.com
                        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                        Join the Slack Community - http://modx.org