如何在在线服务器上运行Laravel API

问题描述 投票:0回答:1

我创建了Laravel CRUD API,它在localhost(没有.htaccess文件)中可以正常工作,但是在实时服务器上失败。当我发送请求时,它返回404 not found error,或根据.htaccess内容下载文件。我应该如何更改.htaccsess文件以使代码正常工作。这是我的.htaccess文件,返回未找到错误。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
php laravel
1个回答
0
投票

有一个'官方'的htaccess,应该为您提供基本的代码以使它正常工作。

请参见https://github.com/laravel/laravel/blob/master/public/.htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

然后,只需确保根指向yourproject/public,使其只能从yourproject/public/index.php引导。

© www.soinside.com 2019 - 2024. All rights reserved.