我有一个在WampServer上运行本地的项目.这是一个类似MVC的结构; 它将URL重写为index.php?url=$1.完整.htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
Run Code Online (Sandbox Code Playgroud)
当我想使用PHP将用户发送到另一个页面location: <location>时,由于重写,所以不能正确地执行此操作(尽管我在技术上总是处于这种状态index.php).
例如,如果我打开http://localhost/project_name/controller/method/并且此控制器的构造函数或方法试图将我发送到:
header('location: another_controller/method'); 送我去
http://localhost/project_name/controller/method/another_controller/method/header('location: /another_controller/method'); 送我去
http://localhost/another_controller/method/但我希望它像这样发送给我:
header('location: /another_controller/method'); 送我去
http://localhost/project_name/another_controller/method/现在我找到的唯一解决方案是:
define('BASE_URL','http://localhost/project_name');
header('location: '.BASE_URL.'/another_controller/method/');
Run Code Online (Sandbox Code Playgroud)
但这并不完美,因为它会导致我必须BASE_URL在域名或文件夹名称发生变化时更改此定义的常量.我也可以创建一个BaseController创建绝对URL的方法,但这种方法基本上也只是前置BASE_URL.
注意: HTML src和href属性不会出现同样的问题,它可以使用相对路径(路径中没有project_name文件夹).但是,我不明白为什么.因为如果标头location导致浏览器将相对URL附加到当前位置,为什么在查找.css或.js文件时它没有相同的行为.
所以......这为我提出了几个问题:
src和href属性不共享此行为?如何访问Facebook页面上"访问者帖子"下的帖子?我一直无法在Graph API中找到这些,并开始怀疑API是否授予访问权限.我试过:
v2.5/me/feed?fields=reactions = Reactions read API requires version v2.6 or higherv2.5/me/feed?fields=comments =不是我想要的评论v2.5/me/comments = Tried accessing nonexisting field (comments) on node type (Page)甚至可以访问VISITOR POSTS?