url 重写 .htaccess 问题
我正在 php 中编写一个 mvc 框架,并尝试使用以下模式重写 url:
www.example.com/contact/send/
读作
www.example.com/index.php?url=contact/send/
所以我可以分解 $_GET['url'] var 并使用到固件中进行路由。
它几乎在任何情况下都工作得很好,唯一的问题是,当我尝试使用也是文件夹的字符串(又名“admin”)时,不带尾部斜杠,网址会公开变量。
像这样:
www.example.com/admin/ - 好的,网址保持原样
www.example.com/admin - 问题就在这里,网址将浏览器重定向到:
www.example.com/admin/?url=admin
$_GET ['url'] 在这两种情况下都已设置并且工作正常,但我希望不公开 'url=admin'。
有什么办法可以做到吗?
谢谢!
.htaccess 是:
重写引擎开启
RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} -d RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$index.php?url=$1 [PT,L]
I'm writing a mvc framework in php, and trying to rewrite urls using this pattern:
www.example.com/contact/send/
to read as
www.example.com/index.php?url=contact/send/
So I can explode the $_GET['url'] var and use into the fw to route.
Its working great in almost any case, the only issue is that when I try to use a string that is a folder too, ak 'admin', without a trailing slash, the url exposes the variables.
Like this:
www.example.com/admin/ - OK, the url stays just like that
www.example.com/admin - Heres the problem, the url redirects browser to:
www.example.com/admin/?url=admin
The $_GET['url'] is set and working ok in both cases, but I wish to doesnt expose the 'url=admin'.
Theres any way to do that?
Thanks!
The .htaccess is:
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{SCRIPT_FILENAME} -d
RewriteCond %{REQUEST_FILENAME} -dRewriteRule ^(.*)$ index.php?url=$1
[PT,L]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你缺少一个! :
当它不是目录时你想重写。
编辑:或者也许是一个例外
I think you are missing a ! :
You want to rewrite when it is NOT a directory.
Edit: Or maybe a exception