它可以通过.htaccess发送查询到另一个文件? 有点解释: index.php处理所有这样的页面:
switch($page) { case 'index': require_once START . '/includes/pages/index.php'; break; case 'another': require_once START . '/includes/pages/another.php'; break; and so on...在.htaccess中:
RewriteRule ^index$ index.php?page=index [L] RewriteRule ^another$ index.php?page=another [L]链接(例如localhost / 84ss7d41):
RewriteRule ^(.*)$ index.php?QUERY_STRING=$1 [L]所以在/includes/pages/index.php中:
if ($_GET['QUERY_STRING']) { $_SERVER['QUERY_STRING'] = $_GET['QUERY_STRING']; $query_string = check_input($_SERVER['QUERY_STRING']); //checking/validating processing further...如何使像这样的一个localhost / 84ss7d41工作方式与现在一样,但没有index.php?如果发生什么事情(文件意外删除),我试图分离我的“项目”,检查/验证数据将工作相同,没有主脚本,它就像:
if (main project file index.php/ || /includes/pages/index.php doesn't exist) { check/validate data with reserve.php }
1 个回复
jalias 2018-12-30
赞同来自:
index.php
,然后您可以使用$_SERVER["REQUEST_URI"]
来决定如何操作。这是前端控制器模式http://en.wikipedia.org/wiki/Front_Controller_pattern的实现 此外,如果apache无法找到index.php
,则请求将转发到reserve.php
虽然,建立这种冗余不一定是“正确”的事情(如果reserve.php也失踪了怎么办?)。对index.php
执行适当的访问控制可能是一种更好的方法。