Codeigniter + Lumen Framework - htaccess 将特定路径重定向到特定文件夹
Codeigniter + Lumen Framework - htaccess redirect certain path to specific folder
我有一个CodeIgniter项目,我最近添加了一个Laravel Lumen API,所以文件夹结构如下
Project
- api/
- application/
- public/
- system/
- .htaccess
- index.php
api/
文件夹中包含 Lumen 框架。通过访问 url localhost/example.com/api/test
和 returns 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/ [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [QSA,R,L]
RewriteCond !^(index\.php|public|robots\.txt)
RewriteCond !^([^\..]+\.php|robots\.txt|sitemap\.xml)
RewriteRule ^(.*)$ index.php?/ [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
它 returns 404 HTTP 代码 by codeigniter
- 通过访问
example.com/api
它 returns 404 HTTP 代码 by lumen
已解决.
好吧,.htaccess 在本地主机上没有任何问题,因为我安装了 apache,而生产服务器中没有。
服务器是 运行 Nginx 而不是 Apache,这是我在请求支持后才发现的。
我有一个CodeIgniter项目,我最近添加了一个Laravel Lumen API,所以文件夹结构如下
Project
- api/
- application/
- public/
- system/
- .htaccess
- index.php
api/
文件夹中包含 Lumen 框架。通过访问 url localhost/example.com/api/test
和 returns 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/ [R=301,L]
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [QSA,R,L]
RewriteCond !^(index\.php|public|robots\.txt)
RewriteCond !^([^\..]+\.php|robots\.txt|sitemap\.xml)
RewriteRule ^(.*)$ index.php?/ [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
它 returns 404 HTTP 代码 by codeigniter - 通过访问
example.com/api
它 returns 404 HTTP 代码 by lumen
已解决.
好吧,.htaccess 在本地主机上没有任何问题,因为我安装了 apache,而生产服务器中没有。
服务器是 运行 Nginx 而不是 Apache,这是我在请求支持后才发现的。