If we look into default .htaccess, we found some lines of code like below:
# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
These code will evaluate every request to our server, even if it's only try to get a small favicon.ico image, a small robots.txt file or "index.php" in the root directory.
The code above perform 1 or 2 IO operation to harddisk: "-f" to check if the requested file is available on hardisk, then if it's not a file then followed by "-d" to determine whether the request is a physical directory or symlink.
I think it's not needed and will add some microsecond (?) to every request, because IO operation known as 'bottleneck' beside database query.
To avoid IO operation (checking existing file or folder), we should modify the code above.
ALTERNATE 1: add .htaccess to physical sub-directories
As found in manager folder, we could add the same .htaccess to every 'static' sub-directories. For example add it to "images" folder.
#.htaccess
RewriteEngine Off
But it's such a wasting time, and this solution also add another IO operation because Apache will check every .htaccess in every subdir.
ALTERNATE 2: add another RewriteCond to the default code
Before making IO operation by -f or -d, we add another RewriteCond to evaluate the REQUEST_URI. This solution is much better because, we only have to manage one .htaccess file.
Make sure you don't create ALIAS of resources same as existing physical subdir.
# The Friendly URLs part
# avoid IO on subdir: extras, media, themes, images, assets, connectors and manager
RewriteCond %{REQUEST_URI} !^(/extras/|/media/|/themes/|/images/|/assets/|/connectors/|/manager/) [NC]
# existing code below
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
But this code also still make an IO operation on non physycal file/folder and also on all files in root directory, such as favicon.ico, robots.txt and index.php.
ALTERNATE 3: split the default code
Split the code: the first part to check the files in root directory, and the second for subdir created by MODx resources. Also make sure you don't create ALIAS of modx resources same as existing physical subdir or file.
# The Friendly URLs part
# Checking files in root directory but only on .html, .txt, .xml and .rss
# IO operation still used if pass the first RewriteCond
# but not applied, for example, to favicon.ico file.
RewriteCond %{REQUEST_URI} ^/([a-z0-9\-_]+)\.(html|rss|xml)$ [NC]
#If there are static html/rss/xml files in root, uncomment below
#RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
# Checking subdir completely without IO operation
RewriteCond %{REQUEST_URI} !^/(extras|media|themes|images|assets|connectors|manager)/ [NC]
RewriteCond %{REQUEST_URI} ^/([a-z0-9\-_]+)/(.*)? [NC]
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
ALTERNATE 4: use another domain or subdomain for serving static files
This solution is out of .htaccess part. So it's should be discussed in another thread
Cheers,
@zaenal
[ed. note: lokamaya last edited this post 11 years, 5 months ago.]