【问题标题】:How to work php front controller using .htaccess?如何使用 .htaccess 工作 php 前端控制器?
【发布时间】:2012-04-23 05:47:19
【问题描述】:

我使用查询字符串做了前端控制器。

例如:

但我需要在不使用查询字符串的情况下这样做。

【问题讨论】:

  • 那么,你到底想要什么?
  • @Chasing Death:在我提到的示例中,我从 quary 字符串中捕获 main 并包含 main.php。现在我需要在不从 quary 字符串中获取“main”的情况下包括 main.php。我在本教程中尝试了这个。 onlamp.com/pub/a/php/2004/07/08/front_controller.html?page=1
  • 其实我需要间接调用控制器。

标签: php .htaccess front-controller


【解决方案1】:

在 .htaccess 中

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule    (.*) controller.php    [L]
 </IfModule>

这会将所有内容重新路由到controller.php;所以你可以像这样访问它:

http://host/main
http://host/contact_form

然后在 controller.php 中你必须解析 $_SERVER['REQUEST_URI'] 以提取传递的参数。

希望对您有所帮助..

【讨论】:

  • 谢谢,这真是太好了。我不喜欢仅仅为了干净的 URL 而使用臃肿的 PHP 控制器库。
猜你喜欢
  • 2015-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-11-07
  • 1970-01-01
  • 2023-04-10
  • 1970-01-01
相关资源
最近更新 更多