问题
I've spent some time on Google and SO trying to figure this out and I have now had to resort to asking yet another mod_rewrite question....
I am using mod_rewrite and for the most part it works fine.
The part I am having problems with is:
# Load pages for health-it while keeping the URL masked
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^health-it/([-a-z0-9]+)/? /health-it/loadPage.php?p=$1 [NC,L]
I have a URI that I want:
/health-it/aimsconsultant
The problem is, mod_rewrite is doing this:
/health-it/aimsconsultant/?p=aimsconsultant
The page still loads but the URI is the issue.
/health-it/aimsconsultant/
Works as expected. It should be noted that /health-it/aimsconsultant is a directory and maybe this is the cause? I believe that Apache redirects to append the trailing slash for directories but why is it appending the query string?
It works perfect for internal pages (no directory for internal pages):
/health-it/aimsconsultant/manufacturer-signup
and
/health-it/aimsconsultant/manufacturer-signup/
work properly.
The only issue is on the first level... This makes no sense to me and I am baffled as to why this is happening. Please, can someone enlighten me on how to fix this and why this is working in this manner?
Thanks for your help
回答1:
OK, sorry, I misread the ? for a $ !
Tried adding this, it seems to to the job:
DirectorySlash Off
By default, it's On, and that's why when Apache tries to get the canonical representation of your URL, it falls back onto the directory.
回答2:
Add a specific entry for the URL version without trailing slash:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^health-it/([-a-z0-9]+)? /health-it/loadPage.php?p=$1 [NC,L]
I've already had this kind of problem, where mod_rewrite ends with appending the query string, even without QSA flag. Don't know the reason why...
来源:https://stackoverflow.com/questions/9704592/mod-rewrite-appends-query-string-when-not-using-trailing-slash