简体   繁体   English

Laravel路线不适合生产

[英]Laravel routes not working on production

I've a Laravel5/angularJS app (beeing Laravel as an api rest and angular for the front-end) 我有一个Laravel5 / angularJS应用程序(作为api休息和前端有角度的Laravel)

At my local environment everything works like charm. 在我当地的环境中,一切都像魅力一样。

But when i upload to a hosting i can only access to the index page, everything else throws a 404. 但是当我上传到托管我只能访问索引页面时,其他一切都会抛出404。

in my shared hosting i have the file-system like this. 在我的共享主机中我有像这样的文件系统。

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

the .htaccess content: .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>

index.php inside laravel-frontend: 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);

and the routes.php 和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');
    ....

So, as i said, i can see login page, but when i want to login i get 404 error 所以,正如我所说,我可以看到登录页面,但是当我想登录时,我得到404错误

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

any clue? 任何线索? any configuration i miss? 我想念的任何配置?

In addition, i have not access to configuration server, i mind i can't edit etc folder hosts, vhosts or similar like i did in my local environment. 另外,我无法访问配置服务器,我介意我无法编辑等文件夹主机,虚拟机或类似我在我的本地环境中所做的。

Assuming you're on an apache2 server on Unix: 假设您在Unix上的apache2服务器上:

  • run the command sudo a2enmod rewrite 运行命令sudo a2enmod rewrite
  • make sure that there's a section of your /etc/apache2/sites-available/000-default.conf that looks like the following. 确保/etc/apache2/sites-available/000-default.conf中有一部分如下所示。 Note that /var/www/html is the root directory default of apache2, yours may be /var/www/html/public or something to that effect. 请注意, /var/www/html是apache2的根目录默认值,你的可能是/var/www/html/public或者那种效果。

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

  • run sudo service apache2 restart 运行sudo service apache2 restart

  • see if that works. 看看是否有效。

I'm not sure how, if someone can give me a theorical answer is welcome. 我不知道如果有人能给我一个理论上的答案是受欢迎的。

I changed the folder structure: 我改变了文件夹结构:

public_html
    laravel-app
        public

the standar laravel way. 标准的laravel方式。

then I configure the .htaccess pointing to the public and the request became to work. 然后我配置.htaccess指向公共,请求变得有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM