I’m having an issue with my rewrites exposing GET variables if the originating request isn’t terminated with a forward slash (/).
Here’s my rule:
# All requests are routed to PHP
RewriteRule ^(.*)$ framework/index.php?framework=$1&%{QUERY_STRING} [L]
If I visit:
everything works great. If I visit:
I get redirected to:
http://www.domain.com/folder/?framework=folder
What gives?
It sounds like
/folderexists in your web root. Since you haven’t sent Apache a slash-terminated URL, and the requested resource is a folder, theDirectorySlashdirective forces a redirect to the corrected URL.Unfortunately,
mod_rewritehas a go at your request before this redirect occurs, and while it doesn’t change the URI that is used in generating the redirect, the changes that it makes to the query string are not separated in a way thatmod_dirknows not to include them. Therefore, when the redirect is sent back to the browser, it includes the query string generated by yourRewriteRule.A potential solution to this (other than turning off
DirectorySlash, which is not recommended for the reasons listed in the documentation) is to performmod_dir‘s work for it as part of your rule set: