Example #1
0
<?php

/**
 * 这里主要是写首页相关的路由
 *
 * @author jiang <*****@*****.**>
 */
Route::get('/', ['as' => 'blog.index.index', 'uses' => 'Home\\IndexController@index']);
Route::get('/index/detail/{id}.html', ['as' => 'blog.index.detail', 'uses' => 'Home\\IndexController@detail'])->where('id', '[0-9]+');
//oauth login
Route::get('/login.html', ['as' => 'blog.login', 'uses' => 'Home\\MembersController@login']);
Route::get('/reg.html', ['as' => 'blog.reg', 'uses' => 'Home\\MembersController@reg']);
Route::get('/login_back.html', ['as' => 'blog.login.back', 'uses' => 'Home\\MembersController@loginback']);
Route::get('/login_out.html', ['as' => 'blog.login.out', 'uses' => 'Home\\MembersController@logout']);
// common routes
Route::any('{class}/{action}.html', ['as' => 'home', function ($class, $action) {
    $touchClass = 'App\\Http\\Controllers\\Home\\' . ucfirst(strtolower($class)) . 'Controller';
    $classObject = new $touchClass();
    if (!class_exists($touchClass) or !method_exists($classObject, $action)) {
        return abort(404);
    }
    return header_cache(call_user_func(array($classObject, $action)), false);
}])->where(['class' => '[0-9a-z]+', 'action' => '[0-9a-z]+']);
Example #2
0
foreach ($redir_prefix as $from => $to) {
    if (strpos($url . '/', $from) === 0) {
        $i = 1;
        $goto = str_replace($from, $to, $url . '/', $i);
        redirect(301, $goto, FALSE, strpos($goto, '//') != FALSE);
        exit;
    }
}
// Initialize $path
$url = '';
// Handle subdomains.
handle_subdomains();
// Append the url part to $path.
$url .= $_GET['url'];
// Send 'Cache-Control' header.
header_cache($url);
// Load the modules.
load_modules($modules);
// If $path is a directory
if (is_dir(DIR_PUB . $url)) {
    // include its default file.
    read_file($url . DEFAULT_FILE);
    // If nothing was found, redirect to 404 error page.
    redirect(404, ERROR_404, $url);
} elseif (file_exists(DIR_PUB . $url)) {
    // check if there its file extension is unnecessary.
    remove_ext($url);
    // If nothing was found,
    read_file_ext($url);
} elseif (strrpos($url, DEFAULT_FILE) === ($diff = strlen($url) - strlen(DEFAULT_FILE))) {
    // redirect to dir/.