为 MVC 应用程序添加尾部斜杠
我正在构建一个基于 MVC 设计模式的应用程序,我希望我的 URL 类似于: http:// /example.com/page/action/。我成功地让它与下面的代码一起工作,但如果 URL 不以斜杠结尾,应用程序就会中断。我已经搜索了所有内容,主要是 Stack Overflow,但我还没有找到适合我的代码的好答案。我尝试修改其他人得到的许多答案,但这也不起作用。
这是我的最新代码(不包括我尝试过的代码):
# Turn on Rewrite Engine
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*) /$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/(.*)/$ ./index.php?p=$1&a=$2 [PT]
我从以下位置得到了一些想法:
我是mod_rewrite的新手,但我不明白为什么我无法获取添加尾部斜杠的代码。看起来是正确的。有人可以帮我吗?谢谢!
I'm building an application based on the MVC design pattern, and I want my URLS to be like: http://example.com/page/action/. I successfully got it to work with the code below, but if the URL doesn't end with a slash, the application breaks. I've searched all over, mostly Stack Overflow, but I haven't found a good answer that works with my code. I've tried to modify many of the answers others got, but that didn't work either.
Here is my latest code (that doesn't include things I've tried):
# Turn on Rewrite Engine
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*) /$1/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/(.*)/$ ./index.php?p=$1&a=$2 [PT]
I got a few ideas from:
I am new to mod_rewrite, but I don't understand why I can't get the code to add a trailing slash. It looks correct. Can someone help me out? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)