3

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]
1
  • Try with adding question mark in line RewriteRule ^(.*)$ index.php?/$1 [L,QSA]. Commented May 21, 2017 at 15:38

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, the problem is in my apache module I think

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.