使用此路由的我的404文件不存在的重定向页
我是新来的,对不起,如果有问题。我在某个地方找到了这条路线,它做得很好,但是当我去Local -Host/blablabal时,只有一个白页,并且不会重定向到我的404错误文件
index.php file.php
<?php
include 'route.php';
$route = new Route();
$route->add('/', function() {
require('config/home_l.php');
});
$route->add('pretraga', function() {
require('config/pretraga.php');
});
$route->submit();
file.php file.php
<?php
/**
* @author Jesse Boyer <[email protected]>
* @copyright Copyright (C), 2011-12 Jesse Boyer
* @license GNU General Public License 3 (http://www.gnu.org/licenses/)
* Refer to the LICENSE file distributed within the package.
*
* @link http://jream.com
*
* @internal Inspired by Klein @ https://github.com/chriso/klein.php
*/
class Route
{
/**
* @var array $_listUri List of URI's to match against
*/
private $_listUri = array();
/**
* @var array $_listCall List of closures to call
*/
private $_listCall = array();
/**
* @var string $_trim Class-wide items to clean
*/
private $_trim = '/\^$';
/**
* add - Adds a URI and Function to the two lists
*
* @param string $uri A path such as about/system
* @param object $function An anonymous function
*/
public function add($uri, $function)
{
$uri = trim($uri, $this->_trim);
$this->_listUri[] = $uri;
$this->_listCall[] = $function;
}
/**
* submit - Looks for a match for the URI and runs the related function
*/
public function submit()
{
$uri = isset($_REQUEST['uri']) ? $_REQUEST['uri'] : '/';
$uri = trim($uri, $this->_trim);
$replacementValues = array();
/**
* List through the stored URI's
*/
foreach ($this->_listUri as $listKey => $listUri)
{
/**
* See if there is a match
*/
if (preg_match("#^$listUri$#", $uri))
{
/**
* Replace the values
*/
$realUri = explode('/', $uri);
$fakeUri = explode('/', $listUri);
/**
* Gather the .+ values with the real values in the URI
*/
foreach ($fakeUri as $key => $value)
{
if ($value == '.+')
{
$replacementValues[] = $realUri[$key];
}
}
/**
* Pass an array for arguments
*/
call_user_func_array($this->_listCall[$listKey], $replacementValues);
}
}
}
}
文件。
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?uri=$1 [QSA,L]
ErrorDocument 404 localhost/404.php
file.htaccess ^(。+)$ index.php?uri = $ 1 [qsa,l]来自.htaccess and Work,但是如何在没有删除的情况下使所有这些工作。对不起,我的糟糕的英语。
I'm new here and sorry if something is wrong. I found this route somewhere and it does a great job but when I go to localhost/blablabal there is just a white page and it doesn't redirect to my 404 error file
index.php file
<?php
include 'route.php';
$route = new Route();
$route->add('/', function() {
require('config/home_l.php');
});
$route->add('pretraga', function() {
require('config/pretraga.php');
});
$route->submit();
route.php file
<?php
/**
* @author Jesse Boyer <[email protected]>
* @copyright Copyright (C), 2011-12 Jesse Boyer
* @license GNU General Public License 3 (http://www.gnu.org/licenses/)
* Refer to the LICENSE file distributed within the package.
*
* @link http://jream.com
*
* @internal Inspired by Klein @ https://github.com/chriso/klein.php
*/
class Route
{
/**
* @var array $_listUri List of URI's to match against
*/
private $_listUri = array();
/**
* @var array $_listCall List of closures to call
*/
private $_listCall = array();
/**
* @var string $_trim Class-wide items to clean
*/
private $_trim = '/\^
.htaccess file
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?uri=$1 [QSA,L]
ErrorDocument 404 localhost/404.php
I remove RewriteRule ^(.+)$ index.php?uri=$1 [QSA,L] from .htaccess and work but how to make all this work without delete this. Sorry for my bad eng..
;
/**
* add - Adds a URI and Function to the two lists
*
* @param string $uri A path such as about/system
* @param object $function An anonymous function
*/
public function add($uri, $function)
{
$uri = trim($uri, $this->_trim);
$this->_listUri[] = $uri;
$this->_listCall[] = $function;
}
/**
* submit - Looks for a match for the URI and runs the related function
*/
public function submit()
{
$uri = isset($_REQUEST['uri']) ? $_REQUEST['uri'] : '/';
$uri = trim($uri, $this->_trim);
$replacementValues = array();
/**
* List through the stored URI's
*/
foreach ($this->_listUri as $listKey => $listUri)
{
/**
* See if there is a match
*/
if (preg_match("#^$listUri$#", $uri))
{
/**
* Replace the values
*/
$realUri = explode('/', $uri);
$fakeUri = explode('/', $listUri);
/**
* Gather the .+ values with the real values in the URI
*/
foreach ($fakeUri as $key => $value)
{
if ($value == '.+')
{
$replacementValues[] = $realUri[$key];
}
}
/**
* Pass an array for arguments
*/
call_user_func_array($this->_listCall[$listKey], $replacementValues);
}
}
}
}
.htaccess file
I remove RewriteRule ^(.+)$ index.php?uri=$1 [QSA,L] from .htaccess and work but how to make all this work without delete this. Sorry for my bad eng..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论