我只是在用 PHP 开发一个小 WebApp,对于路由,我使用AltoRouter。
到目前为止,我只是在我的本地主机上进行离线开发和测试。现在,为了查看服务器上的行为,我上传了我的代码,修复了数据库连接以适应服务器上运行的 MySQL-Server(即 Ubuntu 14.04)并尝试启动它。
首先,我正在为路由做的事情很简单.htaccess
,看起来像这样:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L]
然后,在 myindex.php
中,路由完成
<?php
include 'vendor/altorouter/altorouter/AltoRouter.php';
$router = new AltoRouter();
$router->setBasePath('');
$router->map('GET','/','home.php','home');
$router->map('GET','/datenschutz','datenschutz.php','datenschutz');
$router->map('GET','/impressum','impressum.php','impressum');
$router->map('GET','/header','header.php','header');
$router->map('GET','/jquery','vendor/components/jquery/jquery.js','jquery');
$router->map('GET','/bootstrapjs','vendor/twbs/bootstrap/dist/js/bootstrap.js','bootstrapjs');
$router->map('GET','/bootstrapcss','vendor/twbs/bootstrap/dist/css/bootstrap.css','bootstrapcss');
$router->map('GET','/generalStyle','style.css','generalStyle');
$match = $router->match();
if($match) {
if($match['name'] === 'generalStyle'){
header("Content-Type: text/css");
$fileName = $match['target'];
echo file_get_contents($fileName);
return;
}
require $match['target'];
}
else {
header("HTTP/1.0 404 Not Found");
require '404.php';
}
?>
这在我的本地主机上完美运行,所以一般来说似乎没有问题。
但是,在我的服务器上,当前进到 IP 时,首先似乎它正在工作,因为当仅转到时/
,home.php
文件已正确加载。但是,无论我叫什么其他路线,比如/impressum
,它都不起作用,回到/
,home.php
又起作用了。
现在,替换home.php
(在路由中)impressum.php
也可以,然后我也可以看到正确的文件。总而言之,似乎它总是只有第一条有效的路线。
有谁知道,为什么会发生这种情况或问题是什么?
我尝试直接调用文件,并且(除了一些未加载的脚本等)它的工作,所以去myDomain.com/impressum.php
工作正常,所以它似乎不是文件或某事的问题。
我还尝试将hole项目的权限设置为755,以确保这不是问题,但结果相同。
有任何想法吗?
编辑:我已经尝试了很多,但仍然没有让它工作......但是,我认为这不是“第一条路线”工作,而只有/
-route 工作。其他所有路线都不起作用,但同样,一切都在运行 XAMPP 的 localhost 上运行......