PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, March 14, 2022

[FIXED] Codeigniter + Lumen Framework - htaccess redirect certain path to specific folder

 March 14, 2022     .htaccess, codeigniter, lumen     No comments   

Issue

I have a CodeIgniter project and I recently added a Laravel Lumen API, so the folder structure is the following

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

Inside the api/ folder resides the Lumen framework. Locally it's working perfectly, by accessing the url localhost/example.com/api/test it returns 200 HTTP code.

.htaccess codeigniter root folder:

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 lumen api folder:

<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>

The errors:

  • By accessing example.com/api/test it returns 404 HTTP code by codeigniter
  • By accessing example.com/api it returns 404 HTTP code by lumen

Solution

Solved.

Well, the .htaccess worked without any problem in localhost because I have apache installed, which I don't have in the production server.

The server is running Nginx and not Apache, which I only find out after requesting support.



Answered By - Linesofcode
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing