dongman2721 2013-07-26 11:01
浏览 42

修改$ _SERVER ['REQUEST_URI'],具体取决于index.php所在的目录

I have a problem here:

I have the application that is running on virutalhost: example.com

The application processes all all reqests example.com/* and they fall into the index.php script where the magic happens further.

The components of magic environment variable $ _SERVER ['REQUEST_URI'], everything works nicely, until I wanted to run the application in a subdirectory: example.com/abc/*

My question is:

How can I modify $ _SERVER ['REQUEST_URI'] with entries in .htaccess after entering the example.com/abc/whatever the index.php script in the $ _SERVER ['REQUEST_URI '] was the entry: /whatever and not /abc/whatever?

I made some research, and slowly come to the conclusion that it is only a modification of the $ _SERVER ['REQUEST_URI'] in a index.php script is the one solution?

Has anyone an idea?

Thank you for any help

  • 写回答

1条回答 默认 最新

  • doupai6875 2013-07-26 12:07
    关注

    Try not to use $_SERVER['REQUEST_URI'] for this type of thing.

    Instead use define and then use those definitions throughout your application. So for your subdirectory us this and then use BASE_DIR and BASE_URL throughout your application.

    define("BASE_DIR", "/var/www/abc/");
    define("BASE_URL", "/abc);
    

    If you then need to move it again this is easily done, because you can just change those two variables and you don't need to worry about making sure $_SERVER['REQUEST_URI'] is right.

    define("BASE_DIR", "/var/www/sitename.com/httpdocs/subdir");
    define("BASE_URL", "/subdir);
    

    Note you use these definitions like so

    echo "The base dir is " . BASE_DIR;
    
    评论

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建