In a traditional PHP web server environment you have a root folder and an index.php/index.html file (by default) and requests for the raw URL result in the index.php/index.html file being served. adding index.php/index.html onto the end of the raw URL also results in this file being served. You can also add any pathname relative to the sites root to the end of the URL and that file will be served.

But with drupal you dont have a folder structure like this (except for the index.php file) you have a menu system and drupal generates the pages based on this.

My question is since Drupal is not the web server how does it go about overriding the web server so that if example.com/about.php is entered the server does not try to find about.php in the root folder and return it.

Comments

Sam Moore’s picture

Have a look at the .htaccess file in the docroot - it has a rewrite in it to pass all requests to index.php
Index.php then acts as a router (as in the MVC pattern).

Here's the rewrite:

# Pass all requests not referring directly to files in the filesystem to
# index.php. Clean URLs are handled in drupal_environment_initialize().
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]

nevets’s picture

Building on Sam's comment, when you see a path like www.example.com/node/9, part of the .htaccess "magic" is transform that to www.example.com/index.php?q=node/9. So index.php is always called and the q= tells Drupal what Drupal path to display.

yelvington’s picture

Note the part about "requests not referring directly to files in the filesystem." Drupal isn't overriding anything. If you put "about.php" in your docroot, Apache will happily serve it. If it's missing, the request is handed to Drupal, which then figures out what to do.