rewriterule如何处理无结尾斜杠
我尝试将进入目录的任何内容重定向到另一个目录。我使用的 rewriterule 命令是:
RewriteRule ^VirtualDirectory(.*)$ GENS/RealDirectory$1 [L,NC]
问题是我希望重写对 VirtualDirectory 没有结束斜杠的查询,就好像该查询是针对 VirtualDirectory/
我得到的行为是:
对 VirtualDirectory/ 的查询在没有用户的情况下效果很好注意到 对 VirtualDirectory 的查询效果很好,但 brwoser 中显示的 url 是:GENS/RealDirectory/
我已经尝试了很多方法,但无法获得我想要的行为。
如果我添加一条规则
RewriteRule ^VirtualDirectory$ GENS/RealDirectory/ [L,NC]
来处理该特定情况,它会很好地工作,除了页面的所有资源都被重写到 VirtualDirectory 之前的文件夹中
I try to redirect anything coming into a directory to another. the rewriterule command I use is :
RewriteRule ^VirtualDirectory(.*)$ GENS/RealDirectory$1 [L,NC]
The thing is that I'd like that a query with no end slash to VirtualDirectory to be rewritten as if the query was for VirtualDirectory/
The behaviour I get is :
query to VirtualDirectory/ works great without the user noticing
query to VirtualDirectory workd great but the url shown in the brwoser is : GENS/RealDirectory/
I've tried many things but I can't get the behaviour I want.
If I add a rule
RewriteRule ^VirtualDirectory$ GENS/RealDirectory/ [L,NC]
to handle that specific case, it works great except that all resources of the page are rewrited to the folder before VirtualDirectory
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发生的情况是内部重写没有尾随斜杠,然后 mod_dir 接管并执行浏览器重定向到相同的 URL 但带有尾随斜杠。您可以通过在 .htaccess 文件中使用
DirectorySlash Off
来关闭 mod_dir。如果您希望始终使用尾部斜杠,请尝试将规则更改为:What's happening is the internal rewrite is happening without a trailing slash, then mod_dir takes over and does a browser redirect to the same URL but with a trailing slash. You can turn off mod_dir by using
DirectorySlash Off
in your .htaccess file. If you want the trailing slash always, try changing the rule to this: