dongzhuo0895 2014-02-12 00:53
浏览 30
已采纳

使用htaccess将请求发送到两个php文件

I am trying to redirect some requests to my website from index.php to another file called admin.php

$page = $_SERVER['REQUEST_URI'];
if ( strpos($page, '?') !== false ) {
    $page = strstr($page, '?', true);
}
$page = explode('/', $page);
$page = array_diff($page, ['']);
$page = implode('/', $page);
if ( !$page ) { $page = 'public/home'; }
$file = "pages/{$page}.php";
if ( !is_readable($file) ) {
    $file = 'pages/error/404.php';
}

This code selects the page selected from the user. I have this two file using this code but looking in different folders. How do I configure my .htaccess to redirect all the request to www.mysite.com/admin to the file admin.php and all the rest to index.php?

  • 写回答

1条回答 默认 最新

  • dtoq41429 2014-02-12 00:57
    关注

    You don't. Apache will serve one page at a time.

    Options:

    1. Do everything in either admin.php or index.php.
    2. Do what you need in admin.php, save the rest into $_SESSION, return a 302 redirect to index.php.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥15 统计大规模图中的完全子图问题
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式