drlma06060 2013-03-01 23:16
浏览 109
已采纳

PHP中的PATH_INFO没有文件明显

I have a simple script:

index.php:

<?php

$path= $_SERVER['PATH_INFO'];

if($path)
  echo $path;
else
  echo "No Path Info";

?>

When I run it like so www.website.com/index.php it works. ie) www.website.com/index.php/hello will echo /hello

However, if I go to www.website.com/hello, I get a URL not found error when what I want is that /hello is echoed.

How do I make it so that index.php doesn't have to be present for PATH_INFO to work?!

  • 写回答

3条回答 默认 最新

  • dongye9820 2013-03-01 23:24
    关注

    When a webpage is requested from a server. The server looks at the path (i.e. example.com/this/is/a/path) to figure out which file to serve and from where.

    As I understand it, what you want to do is have your index.php handle all the requests. The way you would do this to use URL Rewriting.

    Assuming you are using an apache web server, you can use something called *mod_rewrite* to do this. See more on mod_rewrite here.

    For the specific rules to use, you probably want to use something like the code in V_K's answer.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题
  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题