从api.php复制到根目录后,找不到路由。

huangapple go评论64阅读模式
英文:

routes from api.php not found after copying htacess on root

问题

我可以访问位于/myproject/routes/web.php中的路由,但无法访问/myproject/routes/api.php中的路由。

我在xampp上安装了Laravel版本8,并将.htaccess复制到我的项目根文件夹,然后将server.php重命名为index.php,这样我可以在web上调用我的项目,如http://localhost/myproject。

我的所有资产都位于/myproject/public/template/,也是可访问的。

以下是我的.htaccess文件:

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

    RewriteEngine On

    # 处理授权头
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # 如果不是文件夹,则重定向末尾的斜杠...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # 发送请求到前端控制器...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
英文:

I can access routes that is in /myproject/routes/web.php but I can't access routes in /myproject/routes/api.php

I installed laravel version 8 on xampp and copy htaccess to root folder of my project then rename server.php to index.php so I can call my project in web like http://localhost/myproject.

all of my assets on /myproject/public/template/ is accessible too

here is my .htaccess file

&lt;IfModule mod_rewrite.c&gt;
    &lt;IfModule mod_negotiation.c&gt;
        Options -MultiViews -Indexes
    &lt;/IfModule&gt;

    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]
&lt;/IfModule&gt;

答案1

得分: 1

确保.htaccess文件位于您的Laravel应用程序的根目录中。

确保RewriteBase已正确设置。它应该指向您的Laravel应用程序的根目录。例如,如果您的Laravel应用程序安装在名为myapp的子目录中,您可以像这样设置RewriteBase

RewriteBase /myapp/

您还可以尝试清除缓存:

php artisan cache:clear
php artisan route:cache
希望这对您有帮助
英文:

make sure that the .htaccess file is in the root directory of your Laravel application.

make sure that the RewriteBase is set correctly. It should point to the root directory of your Laravel application. For example, if your Laravel application is installed in a subdirectory called myapp, you would set the RewriteBase like this:

RewriteBase /myapp/

and you can try clearing the cache

php artisan cache:clear
php artisan route:cache

hopefully that is help you

huangapple
  • 本文由 发表于 2023年7月10日 12:10:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/76650636.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定