httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Philip Pemberton <>
Subject [users@httpd] mod_rewrite - query string appended to URL?
Date Fri, 18 Jul 2008 09:33:15 GMT
I'm trying to track down an issue with a set of rewrite rules that I'm
using to convert links from (and /dir/page/)
format into a query-string for a script. To give a better example:	=>	/index.php?projects/foo	=>	/index.php?projects/foo/

However, any file that exists in htdocs overrides the script. So if I
had a file called 'photo.jpg' in htdocs/projects/foo and someone
requested, Apache would handle it
as a file instead of redirecting to the script. This saves me writing 
more code to handle images, and probably a bit of CPU time as well.

Now, this works great, as long as the URL ends with a forward slash. If
this is not the case, then my script sends out a Location: header to
redirect it, like Apache does with directories -- if you request the
directory /foo, you get a 301 Redirect to /foo/ (which then grabs the
index page).

If the URL doesn't end with a forward slash, the URL goes from to This works fine if 
the directory /htdocs/foo/bar/ doesn't exist. If that directory *does* 
exist, then the user gets sent to 
instead of

These are my rewrite rules, as stored in the .htaccess file:
RewriteEngine On
RewriteBase /

# Apply to primary hosts only
RewriteCond %{HTTP_HOST} ^$ [NC,OR]
RewriteCond %{HTTP_HOST} ^$ [NC]

# This makes sure AWStats can get through
RewriteCond %{REQUEST_URI} !^/awstats.* [NC]

# Additional rules -- temp dir
RewriteCond %{REQUEST_URI} !^/temp.* [NC]

# Enable the next condition if you want physical files to override the CMS
# (this should normally be on, otherwise images, etc. will be forwarded 
to the
# CMS, which is generally not what you'd want to happen)
RewriteRule ^(.*)$ index.php?$1 [L]

----- end of htaccess file

Can anyone see what I'm doing wrong here?


The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:> for more info.
To unsubscribe, e-mail:
   "   from the digest:
For additional commands, e-mail:

View raw message