Laravel 路线不适用于生产

Pad*_*dro 4 php .htaccess shared-hosting laravel angularjs

我有一个 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
Run Code Online (Sandbox Code Playgroud)

.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>
Run Code Online (Sandbox Code Playgroud)

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);
Run Code Online (Sandbox Code Playgroud)

和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');
    ....
Run Code Online (Sandbox Code Playgroud)

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

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

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

此外,我无法访问配置服务器,我介意我无法像在本地环境中那样编辑 etc 文件夹主机、vhosts 或类似内容。

dar*_*ue3 5

假设您在 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

  • 看看是否有效。


Pad*_*dro 2

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

我更改了文件夹结构:

public_html
    laravel-app
        public
Run Code Online (Sandbox Code Playgroud)

标准的 Laravel 方式。

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