我正在考虑一个 MVC(模型、视图、控制器)结构化站点.它托管在 smallbusiness.yahoo 上.(Apache) 他们将托管限制为 php(和 mysql),我无法编辑服务器配置.这意味着没有 .htaccess 文件!找了很久的解决方案,都涉及到编辑服务器配置.我正在寻找一种仅用 php 本身重写 URL 的方法.
I have a MVC (Model, View, Controller) structured site that I'm thinking about. It's hosted on smallbusiness.yahoo. (Apache) They limit the hosting to php (and mysql), and there's no way I can edit the server configurations. That means no .htaccess files! I have searched for the solution for a long time, but they all involve editing the server configurations. I am looking for a way to rewrite URLs with only php itself.
我想做 URL 重写,以便控制器可以通过 URL 接收参数.我知道 Codeigniter 会这样做,但我确实想了解它是如何做到的.
I want to do URL rewriting so that the controller(s) can receive parameters through the URL. I know Codeigniter does this, but I do want to LEARN how it does it.
例如,像这样:
example/page.php?page=whatever
example/page.php?page=whatever
变成
example/page/whatever 或
example/page/whatever OR
example/whatever
example/whatever
我看过一些关于 $_SERVER['PATH_INFO'] 的例子,但我不明白它的作用.我试过了
I've seen some examples with $_SERVER['PATH_INFO'], but I don't understand what that does. I've tried
$_SERVER['PATH_INFO'] = '/';但这并没有起到任何作用......将不胜感激!
But that did nothing... Help would be greatly appreciated!!
推荐答案这是我能找到的最接近的东西.严格来说,即使是 WordPress 也会修改 .htaccess 以允许他们自己的模块来管理重写.我觉得奇怪的是,他们会完全禁止所有 .htaccess 更改.你试过了吗?甚至 ASP.NET 也需要修改 web.config 才能使用重写.
This is the closest thing I could find. Strictly speaking, even WordPress modifies the .htaccess to allow their own module to manage the rewriting. I find it odd that they would completely disallow all .htaccess changes. Have you given it a try? Even ASP.NET requires a web.config modification to use rewrites.
pure-essence/2007/06/29/simple-php-path-rewrite/
显然,如果 .htaccess 被完全禁止,最后一个解决方案将无济于事,但在您实际使用 PHP 的情况下,这种情况很少见.我可以看到他们不允许覆盖,但这通常只适用于索引和目录选项之类的东西.
Obviously the last solution wouldn't help if .htaccess is disallowed entirely, but that's rarely the case where you can actually use PHP. I can see them disallowing overrides, but that usually only applies to things like indexes and directory options.
更多推荐
如何仅在 PHP 中重写 URL?
发布评论