【问题标题】:Codeigniter + Lumen Framework - htaccess redirect certain path to specific folderCodeigniter + Lumen Framework - htaccess 将特定路径重定向到特定文件夹
【发布时间】:2021-12-17 09:55:02
【问题描述】:

我有一个CodeIgniter项目,最近添加了一个Laravel Lumen API,所以文件夹结构如下

Project
 - api/
 - application/
 - public/
 - system/
 - .htaccess
 - index.php

在api/ 文件夹内是 Lumen 框架。在本地它运行良好,通过访问 url localhost/example.com/api/test 它返回 200 HTTP 代码。

.htaccesscodeigniter 根文件夹:

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>

.htaccesslumen 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 它返回 404 HTTP 代码codeigniter
  • 通过访问example.com/api,它返回 404 HTTP 代码 按流明

【问题讨论】:

    标签: .htaccess codeigniter lumen


    【解决方案1】:

    已解决。

    嗯,.htaccess 在 localhost 中没有任何问题,因为我安装了 apache,而我在生产服务器中没有。

    服务器运行的是 Nginx 而不是 Apache,我是在请求支持后才发现的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-08
      • 1970-01-01
      • 1970-01-01
      • 2013-09-23
      • 2014-11-21
      • 1970-01-01
      相关资源
      最近更新 更多