我有一個 CodeIgniter 專案,我最近添加了一個 Laravel Lumen API,所以檔案夾結構如下
Project
- api/
- application/
- public/
- system/
- .htaccess
- index.php
該api/檔案夾內是Lumen 框架。在本地,它運行良好,通過訪問 url,localhost/example.com/api/test它會回傳 200 HTTP 代碼。
.htaccess codeigniter 根檔案夾:
Options -Indexes
Options FollowSymLinks
# Set the default file for indexes
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [QSA,R,L]
RewriteCond $1 !^(index\.php|public|robots\.txt)
RewriteCond $1 !^([^\..] \.php|robots\.txt|sitemap\.xml)
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
ErrorDocument 404 index.php
</IfModule>
.htaccess 流明api檔案夾:
<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]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
<Files .env>
Order allow,deny
Deny from all
</Files>
錯誤:
- 通過訪問
example.com/api/test它通過codeigniter回傳404 HTTP代碼 - 通過訪問
example.com/api它通過流明回傳404 HTTP代碼
uj5u.com熱心網友回復:
解決了。
好吧,.htaccess 在 localhost 中沒有任何問題,因為我安裝了 apache,而我在生產服務器中沒有。
服務器正在運行 Nginx 而不是 Apache,我只有在請求支持后才發現。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/350139.html
下一篇:重寫規則不斷顯示內部服務器錯誤
