Adi Sparta
Adi Sparta

Reputation: 525

Remove index.php in code igniter for subfolder

I have some problem. In development I'm using php 7 and my website work well. But in production it using php 5.4 and I have problem in removing index.php. My website hosted in subfolder just like myhost/mywebsitefolder.

The problem is when using url function. example, when I accesing 'dashboard' page it will redirect to 'login' page and the url is like myhost/mywebsitefolder/login and it return 404 page not found. When I add index.php before login (myhost/mywebsitefolder/index.php/login) it work well but I must replace all of my url by adding index.php. Are there any solution. My .htaccess is just like this.

RewriteEngine on
RewriteBase /mywebsitefolder/
RewriteCond $1 !^(index.php|resources|gallery|json|slider|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Upvotes: 3

Views: 1993

Answers (1)

JP. Aulet
JP. Aulet

Reputation: 4398

Try with a slash before the dots, like:

DirectoryIndex index.php

<IfModule mod_rewrite.c>

  RewriteEngine on
  RewriteBase /mywebsitefolder
  RewriteCond $1 !^(index\.php|resources|gallery|json|slider|robots\.txt)
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d 
  RewriteRule ^(.*)$ index.php/$1 [L,QSA]

</IfModule>

<IfModule !mod_rewrite.c>
  ErrorDocument 404 index.php
</IfModule> 

And in application/config/config.php and clear the index page config value:

// Old
$config['index_page'] = "index.php";

// New
$config['index_page'] = "";

Sometimes you need to enable it the rewrite module, run "apache2 enable module rewrite":

sudo a2enmod rewrite

You need to restart the webserver to apply the changes:

sudo service apache2 restart

Hope it works!

If no, there is others threads with the same problem,you can take a look: - Remove index.php from codeigniter in subfolder - Remove index.php from Codeigniter URL in subfolder with Wordpress in root - Using htaccess to remove codeigniter index.php in a subdirectory

Upvotes: 3

Related Questions