我目前已将laravel 5.1应用程序托管到我的1and1.com服务器上,除了根路由之外,我在所有路由中都遇到404未找到的错误,即www.example.com/server /
根路由正在处理get请求,但所有其他路由都是404找不到,一切都在localhost中正常工作。
我的应用程序文件夹结构:
-example.com
您可以看到我删除了默认的laravel公用文件夹并将内容移动到root。
我的.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteCond %{REQUEST_URI} !^ RewriteRule ^(.*)$ /$1 [L] </IfModule>
我的Index.php
<?php
/**
* Laravel - A PHP Framework For Web Artisans
*
* @package Laravel
* @author Taylor Otwell <taylorotwell@gmail.com>
*/
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels nice to relax.
|
*/
require __DIR__.'/bootstrap/autoload.php';
/*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/
$app = require_once __DIR__.'/bootstrap/app.php';
/*
|--------------------------------------------------------------------------
| Run The Application
|--------------------------------------------------------------------------
|
| Once we have the application, we can handle the incoming request
| through the kernel, and send the associated response back to
| the client's browser allowing them to enjoy the creative
| and wonderful application we have prepared for them.
|
*/
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture()
);
$response->send();
$kernel->terminate($request, $response);
Server.php
/**
* Laravel - A PHP Framework For Web Artisans
*
* @package Laravel
* @author Taylor Otwell <taylorotwell@gmail.com>
*/
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
// This file allows us to emulate Apache's "mod_rewrite" functionality from the
// built-in PHP web server. This provides a convenient way to test a Laravel
// application without having installed a "real" web server software here.
if ($uri !== '/' && file_exists(__DIR__.''.$uri)) {
return false;
}
require_once __DIR__.'index.php';
routes.php文件
Route::get('/', function(){
echo'test';exit();
});//test
Route::get('/s', function(){
echo'testss';exit();
});//test
现在如果你看到第一条路线工作正常,但是当我做www.example.com/server/s时,这就得不到404了。
答案 0 :(得分:2)
如果您的项目迁移到新服务器,则可能是因为您使用默认项目文档根配置,因此可以禁用它以默认读取.htaccess文件。您需要更改&#34;无&#34;中的AllowOverride选项。到&#34;所有&#34; (例如)/etc/httpd/conf/httpd.conf
中的选项值(如果是centos):
<Directory /var/www/html/public>
...
AllowOverride All
...
</Directory>
答案 1 :(得分:1)
另外还有Alex,如果你正在运行apache,请尝试
CStr(Year({Date}) + 1, 0, "")
并重新加载apache
sudo a2enmod rewrite
希望这有帮助!
答案 2 :(得分:0)
每当您在共享服务器上托管laravel应用程序时,都需要分离公用文件夹。
公用文件夹的所有内容都应该转到服务器的public_html
文件夹,而所有其他文件夹都需要转到根文件夹..
因此,为了让您前进,首先在服务器根目录中创建一个名为laravel-app
的目录。在此文件夹中,上传所有文件夹和文件,但不上传public folder
。
上传完所有文件后,将public
文件夹的内容上传到public_html
文件夹。
现在,您需要告诉laravel您已更改文件夹的默认结构。为此,请打开位于index.php
文件夹内的public_html
文件。
替换此行:
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
这一行:
require __DIR__.'/../laravel-app/bootstrap/autoload.php';
$app = require_once __DIR__.'/../laravel-app/bootstrap/app.php';
现在,重新上传index.php文件,你应该得到所需的输出。
希望这会帮助你。快乐的编码。欢呼声。