英文:
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
<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>
答案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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论