AltoRouter 没有正确进行路由 [英] AltoRouter not doing the routing correctly

查看:50
本文介绍了AltoRouter 没有正确进行路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是用 PHP 开发一个小 Web 应用程序,用于路由,我使用 AltoRouter.

I'm just developing a little WebApp with PHP and for routing, I use AltoRouter.

到目前为止,我只是离线开发和测试,所以在我的本地主机上.现在,为了查看服务器上的行为,我上传了我的代码,修复了数据库连接以适合在服务器上运行的 MySQL 服务器(即 Ubuntu 14.04)并尝试启动它.

So far, I was only developing and testing offline, so on my localhost. Now, to see the behaviour on a server, I uploaded my code, fixed the database connection to fit for the MySQL-Server running on the server (which is Ubuntu 14.04) and tried to get it started.

首先,我为路由做的是一个简单的.htaccess,看起来像这样:

First, what I'm doing for the routing, is a simple .htaccess, looking like that:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.php [L] 

然后,在我的index.php中,路由完成

And then, in my index.php, the routing is done

<?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';
}

?>

这在我的本地主机上完美运行,所以一般来说似乎没有问题.

This is perfectly working on my localhost, so there doesn't appear to be a problem in general.

但是,在我的服务器上,当前进到 IP 时,它首先看起来是有效的,因为当只转到 / 时,home.php 文件正确加载.但是,无论我调用什么其他路径,比如 /impressum,它都不起作用,回到 /home.php 又开始工作了.

However, on my server, when heading forward to the IP, it first seems, that it's working, because when only going to /, the home.php file is loaded correctly. But, whatever other route I call, like /impressum, it's not working, going back to /, the home.php is working again.

现在,将 home.php(在路由中)替换为 impressum.php 也可以正常工作,然后我也可以看到正确的文件.总而言之,似乎只有第一条路线有效.

Now, replacing home.php (in the route) with impressum.php is working as well, then I can see the correct file as well. So to summarize, it's seems like it's always only the first route that is working.

有没有人知道为什么会发生这种情况或问题是什么?

Does anybody have an idea, why this happens or what the problem is?

我尝试直接调用文件,并且(除了一些未加载的脚本等)它的工作正常,所以转到 myDomain.com/impressum.php 工作正常,所以它没有好像是文件或者某事的问题.

I tried to call the files directly, and (besides some scripts not loaded etc.) its working, so going to myDomain.com/impressum.php is working fine, so it doesn't seem to be a problem of the file or sth.

我还尝试将hole项目的权限设置为755,以确保这没有问题,但结果相同.

I also tried to set the permission of the hole project to 755, to be sure it's not a problem with that, same results though.

有什么想法吗?

我一直在尝试很多,但仍然没有让它工作......但是,我想,这不是第一条路线"工作,而只是/-route,它正在工作.其他所有路线都不起作用,但同样,一切都在运行 XAMPP 的本地主机上运行...

I've been trying around a lot, but still didn't got it working.... However, I figured, that it's not "the first route" working, but only the /-route, which is working. Every other route isn't working, but again, everything is working on localhost with XAMPP running...

推荐答案

终于把问题解决了..

这一切都与 PHP、AltoRouter、htaccess 或其他任何东西无关...

It all wasn't about the PHP, AltoRouter, htaccess or whatever...

解决方案是在我的 vhost-config 的 Directory 中将 AllowOverride 设置为 All....

The solution was to set AllowOverride to All in the Directory of my vhost-config....

这篇关于AltoRouter 没有正确进行路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆