Laravel路线不适合生产

时间:2017-02-12 19:59:36

标签: php angularjs .htaccess laravel shared-hosting

我使用的是Laravel5 / angularJS应用程序(将Laravel作为api休息和角度为前端)

在我当地的环境中,一切都像魅力一样。

但是当我上传到托管我只能访问索引页面时,其他一切都会抛出404.

在我的共享主机中我有这样的文件系统。

public_html
    laravel-backend (it has app, bootstrap, confi...etc, all laravel app)
    laravel-frontend (it would be like the public folder of the laravel default file system)
    .htaccess

.htaccess内容:

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{HTTP_HOST} anotherAppDomainAtSharedServer$ [NC]
    RewriteCond %{REQUEST_URI} !/.*$
    RewriteRule ^(.*)$ /$1 [L]

    RewriteCond %{HTTP_HOST} laravelAppDomain$ [NC]
    RewriteCond %{REQUEST_URI} !^/laravel-frontend/.*$
    RewriteRule ^(.*)$ /laravel-frontend/$1 [L]

</IfModule>
laravel-frontend里面的

index.php:

require __DIR__.'/../laravel-backend/bootstrap/autoload.php';
$app = require_once __DIR__.'/../laravel-backend/bootstrap/app.php';


$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);

$response = $kernel->handle(
    $request = Illuminate\Http\Request::capture()
);

$response->send();

$kernel->terminate($request, $response);

和routes.php

Route::get('/', function () {
    return view('index');
});

Route::group(['prefix' => 'api/v1'], function(){
    Route::resource('authenticate', 'AuthenticateController', ['only' => ['index']]);
    Route::post('authenticate', 'AuthenticateController@authenticate');
    ....

所以,正如我所说,我可以看到登录页面,但是当我想登录时,我得到404错误

http://laravelAppDomain/laravel-backend/api/v1/authenticate 404 (Not Found)
NotFoundHttpException in RouteCollection.php line 161:

任何线索?我想念的任何配置?

此外,我无法访问配置服务器,我想我不能像我在本地环境中那样编辑等文件夹主机,虚拟机或类似文件。

2 个答案:

答案 0 :(得分:4)

假设你在Unix上使用apache2服务器:

  • 运行命令sudo a2enmod rewrite
  • 确保/etc/apache2/sites-available/000-default.conf的某个部分如下所示。请注意,/var/www/html是apache2的根目录默认值,您的可能是/var/www/html/public或类似的东西。

    <Directory /var/www/html> AllowOverride All </Directory>

  • 运行sudo service apache2 restart

  • 看看是否有效。

答案 1 :(得分:0)

我不确定如果有人能给我一个理论上的答案是受欢迎的。

我更改了文件夹结构:

public_html
    laravel-app
        public

标准的laravel方式。

然后我配置.htaccess指向公共,请求开始工作。

相关问题