I have spent the last couple of days working on this. Although Joomla 1.07 returns 404 headers for non existant content pages, it still processes a lot of unwanted content (gif,jpg,css, etc...). I wanted to reduce this processing and let the server handle it on its own.
On older sites (pre 1.07) I consistantly got the front page, even when typing in a nonexistant graphics filename. In addition, subdomains of the primary domain and add-on domains, which live on my server in subdirectories of the main domain, did the same (the primary domain was pre 1.07).
I finally figured a few things out. The existing .htaccess file has this line in it:
- Code: Select all
RewriteCond %{REQUEST_FILENAME} !\.(jpg|jpeg|gif|png|css|js|pl|txt)$
Which is applied with this rule:
- Code: Select all
RewriteRule ^(.*) index.php
This means that apache will look first to see if it has a rule applied to (.*) - everything, then start processing them according to its rules of inheritance. In my case, my ISP has set the mod_rewrite module to inherit rule sets prom parent directories, and the virtual host directives. I suspect that most do to ensure that the virtual host directives are not sidestepped..
So, my server was processing the rulesets for each parent directory, that led to the directory that contained the .htaccess file it was currently processing, in thier order starting from the docroot. For example, running a test on a nonexistant file http://domain.com/test/nothere.jpg it was processing rules from the .htaccess files contained in /server_docroot/user_dir/public_html/primary_domain/add_on_domain/test_directory. In my case, this meant it was processing the .htaccess files from the primary_domain, add_on_domain, and test_directory directories.
I used the standard (1.07) rewrite rules on the test directory, but was consistantly getting the front page no matter what I did. After some futzing around (two days worth) I fnailly was able to determine that the Apache environment variable we were testing was changing with each successful RewriteRule in each of these directories. So the {REQUEST_FILENAME} was getting constantly turned into 'index.php' leading to unmatched rulesets and thus not getting the right action for the rewrite. In each case, the base ruleset for the accessed domain ended up winning the war, and I inevitably ended up on the front page for that domain, even when trying to access these non-existant css and jpg files.
To correct the problem, I started testing on a more constant variable, which in my case turned out to be {REQUEST_URI}. It stayed constant and always contained the actual request (minus the domain). But still had the problem, even though I was getting more succesful matches. Non-existant jpg and css files still brought me back to the accessed domain's front page.
After spending some time (again) futzing with the RewriteCond's, I finally found a way to consistantly return the front page only on requests for non-existant .htm, .html, .php, and directory requests (like Joomla sef URLs).
I replaced the standard line:
- Code: Select all
RewriteCond %{REQUEST_FILENAME} !\.(jpg|jpeg|gif|png|css|js|pl|txt)$
With this:
- Code: Select all
RewriteCond %{REQUEST_URI} (/|\.htm|\.php|\.html|#.*|\?.*|/[^.]*)$ [NC]
I haven't had any problems since. It has worked flawlessly since I made this change, no matter what directory or domain I have accessed it from. I took the time to change this on each base installation, regardless of version, and it has worked like a champ, each still able to access its own SEF URL's.
Here's the code, last modified February 10th (for clarity - no functional changes):
- Code: Select all
######COPYRIGHT##########
# .htaccess file for Joomla/Mambo SEF useage
# Copyright 2006 Steve Graham Contact me at http:/coders.mlshomequest.com/
# Licensed under the LGPL. You are free to use and include this file in
# any project or codebase subject to the LGPL license at:
# http://www.gnu.org/copyleft/lesser.html
######END COPYRIGHT#######
##
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE
#
# The line just below this section: 'Options FollowSymLinks' may cause problems
# with some server configurations. It is required for use of mod_rewrite, but may already
# be set by your server administrator in a way that dissallows changing it in
# your .htaccess file. If using it causes your server to error out, comment it out (add # to
# beginning of line), reload your site in your browser and test your sef url's. If they work,
# it has been set by your server administrator and you do not need it set here.
#
# Only use one of the two SEF sections that follow. Lines that can be uncommented
# (and thus used) have only one #. Lines with two #'s should not be uncommented
# In the section that you don't use, all lines should start with #
#
# For Standard SEF, use the standard SEF section. You can comment out
# all of the RewriteCond lines and reduce your server's load if you
# don't have directories in your root named 'component' or 'content'
#
# If you are using a 3rd Party SEF or the Core SEF solution
# uncomment all of the lines in the '3rd Party or Core SEF' section
#
##### SOLVING PROBLEMS WITH COMPONENT URL's that don't work #####
# SPECIAL NOTE FOR SMF USERS WHEN SMF IS INTEGRATED AND BRIDGED
# OR ANY SITUATION WHERE A COMPONENT's URL's AREN't WORKING
#
# In both the 'Standard SEF', and '3rd Party or Core SEF' sections the line:
# RewriteCond %{REQUEST_URI} ^(/component/option,com) [NC,OR] ##optional - see notes##
# May need to be uncommented. If you are running your Joomla/Mambo from
# a subdirectory the name of the subdirectory will need to be inserted into this
# line. For example, if your Joomla/Mambo is in a subdirectory called '/test/',
# change this:
# RewriteCond %{REQUEST_URI} ^(/component/option,com) [NC,OR] ##optional - see notes##
# to this:
# RewriteCond %{REQUEST_URI} ^(/test/component/option,com) [NC,OR] ##optional - see notes##
#
##
## Can be commented out if causes errors, see notes above.
Options FollowSymLinks
#
# mod_rewrite in use
RewriteEngine On
# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla/MamboDirectory (just / for root)
# RewriteBase /
########## Begin Standard SEF Section
## ALL (RewriteCond) lines in this section are only required if you actually
## have directories named 'content' or 'component' on your server
## If you do not have directories with these names, comment them out.
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_URI} ^(/component/option,com) [NC,OR] ##optional - see notes##
RewriteCond %{REQUEST_URI} (/|\.htm|\.php|\.html|/[^.]*)$ [NC]
RewriteRule ^(content/|component/) index.php
#
########## End Standard SEF Section
########## Begin 3rd Party or Core SEF Section
#
#RewriteCond %{REQUEST_URI} ^(/component/option,com) [NC,OR] ##optional - see notes##
#RewriteCond %{REQUEST_URI} (/|\.htm|\.php|\.html|/[^.]*)$ [NC]
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule (.*) index.php
#
########## End 3rd Party or Core SEF Section
I tested on Linux only, haven't tried this on my Apache/Windows test server yet, but wanted to pass this along for the benefit of others who were experiencing the same thing.
It works flawlessly, and I always get the server's 404 error for any nonexistant file/directory that is not .html, .htm, .php, or a directory.
If you are going to try this, I would suggest backing your old .htaccess file up (obviously), but I think I nailed it.
Consistant 404s, no more potential loops for nonexistant files, and no more Joomla instantiation (even with 1.07 and its 404 page) for these non-existant files.
GRAM











