问题描述
我花了一些时间在Google和SO上试图弄清楚这一点,现在我不得不诉诸另一个mod_rewrite问题....
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....
我正在使用mod_rewrite,并且在大多数情况下都可以正常工作.
I am using mod_rewrite and for the most part it works fine.
我遇到问题的部分是:
# 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]
我有一个想要的URI:
I have a URI that I want:
/health-it/aimsconsultant
问题是,mod_rewrite正在这样做:
The problem is, mod_rewrite is doing this:
/health-it/aimsconsultant/?p=aimsconsultant
页面仍然加载,但是URI是问题.
The page still loads but the URI is the issue.
/health-it/aimsconsultant/
按预期工作.应该注意的是/health-it/aimsconsultant是一个目录,也许这是原因吗?我相信Apache重定向后会在目录后添加斜杠,但是为什么还要在查询字符串后添加后缀?
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
和
/health-it/aimsconsultant/manufacturer-signup/
正常工作.
唯一的问题是在第一层上……这对我来说毫无意义,我对为什么会发生这种情况感到困惑.拜托,有人可以启发我如何解决此问题以及为什么这种方法如此起作用吗?
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?
感谢您的帮助
推荐答案
好的,对不起,我看错了?只需$!
OK, sorry, I misread the ? for a $ !
尝试添加它,似乎对工作有帮助
Tried adding this, it seems to to the job:
DirectorySlash Off
默认情况下,它为On,这就是为什么当Apache尝试获取URL的规范表示时,它会退回到目录中的原因.
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.
这篇关于不使用尾部斜杠时,mod_rewrite附加查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!