httpd-users mailing list archives

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

www.example.com/projects/foo	=>	/index.php?projects/foo
www.example.com/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 www.example.com/projects/foo/photo.jpg, 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
www.example.com/foo/bar to www.example.com/foo/bar/. This works fine if 
the directory /htdocs/foo/bar/ doesn't exist. If that directory *does* 
exist, then the user gets sent to www.example.com/foo/bar/?foo/bar/ 
instead of www.example.com/foo/bar/.

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

# Apply to primary hosts only
RewriteCond %{HTTP_HOST} ^philpem.me.uk$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.philpem.me.uk$ [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)
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} !-f
RewriteRule ^(.*)$ index.php?$1 [L]

----- end of htaccess file

Can anyone see what I'm doing wrong here?

Thanks,
Phil.


---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message