CodeIgniter Forums
CI 4 remove index.php - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Installation & Setup (https://forum.codeigniter.com/forumdisplay.php?fid=9)
+--- Thread: CI 4 remove index.php (/showthread.php?tid=78161)

Pages: 1 2


RE: CI 4 remove index.php - CsurveyVN - 03-14-2022

(12-07-2020, 01:21 PM)captain-sensible Wrote: i've got apache 2.4  runnig on slackware -current and no problem getting rid of index.php in url.

From memory getting rid of index.php in url was quite prominent in docs , i can't quickly find it but its in docs somewhere
app/config/App.php
Code:
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
public $indexPage = '';

(12-08-2020, 02:16 AM)demyr Wrote: You can try the steps here : Stackoverflow

The answer says:

Step 1: In public/ directory, copy index.php and .htaccess to your root project directory.
Step 2: In the root project directory, open index.php and edit the following line:
   
             index.php -> $pathsPath = FCPATH . '../app/Config/Paths.php';
to
            index.php => $pathsPath = FCPATH . 'app/Config/Paths.php';
thanks pro


RE: CI 4 remove index.php - boddah85 - 11-08-2022

(12-29-2020, 12:29 PM)InsiteFX Wrote: You can also remove it by using .htaccess in the root with index.php by adding this
to the .htaccess file.

Code:
   # Remove index.php from URL
   RewriteCond %{HTTP:X-Requested-With} !^XMLHttpRequest$
   RewriteCond %{THE_REQUEST}      ^[^/]*/index\.php [NC]
   RewriteRule ^index\.php(.*)$     $1 [R=301,NS,L]

Thanks, it helped in almost all cases. However i have a problem with one client. When im trying domain.com/index.php/page/1 it correctly returns domain.com/page/1. But when im trying domain.com/index.php it redirects to domain.com/var/www/domain.com/public  Huh

My htaccess
Code:
# Disable directory browsing
Options All -Indexes

# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------

# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymLinks must be enabled for this to work.
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On

# If you installed CodeIgniter in a subfolder, you will need to
# change the following line to match the subfolder you need.
# http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewritebase
# RewriteBase /

# Redirect Trailing Slashes...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^(.*)/$ /$1 [L,R=301]

RewriteCond %{HTTP_HOST} !^www\.
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

    RewriteCond %{HTTPS} off
    RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    # Rewrite "www.example.com -> example.com"
# RewriteCond %{HTTPS} !=on
# RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
# RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

# Checks to see if the user is attempting to access a valid file,
    # such as an image or css document, if this isn't true it sends the
    # request to the front controller, index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\s\S]*)$ index.php/$1 [L,NC,QSA]

# Remove index.php from URL
RewriteCond %{HTTP:X-Requested-With}    !^XMLHttpRequest$
RewriteCond %{THE_REQUEST}              ^[^/]*/index\.php [NC]
RewriteRule ^index\.php(.*)$            $1 [R=301,NS,L]

# Ensure Authorization header is passed along
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</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>

# Disable server signature start
    ServerSignature Off
# Disable server signature end



RE: CI 4 remove index.php - ikesela - 11-08-2022

use default .htaccess from framework. just replace this line:

FROM ( this is defaul form framework but not working correctly for me, replace with new rule below);
# RewriteRule ^([\s\S]*)$ index.php/$1 [L,NC,QSA]

TO (change to this)
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]