Forum Moderators: phranque
I have around 15 sites on my server that have recently been the target of scripts attempting RFI exploits and the like. Most are custom php/mysql, some are static html and some are Mambo/Joomla.
Based on the excellent advice found in the forum, I have created an .htaccess file to keep out these unwanted visitors with a combination of blocks for user-agent and IP, and all seems to be working.
For ease of maintenance, I have one .htaccess file which is linked to from each site folder so I can update centrally.
All well and good so far but I have run into a problem with the SEF rewrite required by the Mambo/Joomla sites. I have the correct redirect lines in the file so that works, and for the other php sites it works to redirect queries for non-existent pages to index.php so that's all good.
My problem arises with the static sites which do not have an index.php file, only index.html. Any false query throws up a 404 page, which again is not a major problem.
However, seeing as I'm so pleased at being able to centralise my .htaccess file what I'd like to do is improve on the redirect so it will check for index.php first and if that isn't there, will default to index.html
Sure I can put an index.php file in the half dozen folders that don't have one, or have two .htaccess files, one for each case, but I do like to keep things neat and tidy, as I'm sure you'll understanbd.
So, is this possible at all?
Here is the Joomla SEF redirect:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php
Anyway, just to update I did read the mod_rewrite manual and I tried to use the Skip directive like this,
RewriteCond %{REQUEST_URI} !index\.php
RewriteRule ^(.*) index.php [S=1]
RewriteRule ^(.*) index.html
which worked fine on the static sites but managed to bork the original function so no joy there.
# If index.php does not exist, and index.html does
# exist, rewrite index.php requests to index.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/index.html -f
RewriteRule ^index\.php$ /index.html [L]
#
# Rewrite requested URL=paths which do not resolve to existing
# files or directories to the index.php script
RewriteCond $1 !^index\.php$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
Jim
thanks for the tip on comments, I generally do use them - time and experience has taught me that much - but didn't include them here for the sake of simplicity.
now if i can only figure out why mod_rewrite isn't working the same on my new test server as it does on the live site, i could be taking the weekend off...
cheers