2

I'm struggling with removing the 'index.php' part of my CodeIgniter URL. I'm using CodeIgniter version 3.1.2. I've followed all steps on other questions about this:

  • Changed $config['index_page'] = 'index.php' to $config['index_page'] = ''
  • Changed $config['uri_protocol'] = 'AUTO' to $config['uri_protocol'] = 'REQUEST_URI'
  • Added a .htaccess file in the root folder of my project with the following code:

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

However when I try to access my site, I get the following error code.

Not Found

The requested URL /Toneel/Site/index was not found on this server.

The rewrite module is turned on in my Apache Server. Can anyone help me out with this issue?

1
  • Add RewriteBase /your_project_name after RewriteEngine On when running at localhost and just RewriteBase / when you upload the code to a server. Commented Feb 25, 2017 at 11:34

4 Answers 4

4

This setting worked for me.

$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

.htaccess

<IfModule mod_rewrite.c>
  RewriteEngine On
  #RewriteBase /

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ index.php [QSA,L]
</IfModule>

To allow overriding htaccess in Apache Configuration you have to edit and change /apache2.conf file to

AllowOverride All

And restart server.

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

4 Comments

I think the AllowOverride All was the issue. I changed it to All and the error changed from "Not Found" to: Forbidden You don't have permission to access /Toneel/Site/index on this server.
My Apache error logs say the following: Options FollowSymLinks and SymLinksIfOwnerMatch are both off, so the RewriteRule directive is also forbidden due to its similar ability to circumvent directory restrictions
Which Operating system you are using?
Windows 10 Professional
1

Try this code in .htaacess:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$1 [PT,L]

2 Comments

Thank you for your answer but this code gives the same error result. I've tried about every possible .htaccess code I could find and none of them work
after rewrite module turned on did you restart server @Yaniiick
0

Try this in your .htaccess file

RewriteEngine On
RewriteBase /yourfolderhere/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Comments

0

In my case, it works with:

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /project-name

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^ index.php [QSA,L]
</IfModule>

** Important, this should be in an .htaccess file in the root of your project.

In config should be like this:

$config['base_url'] = 'http://your-url-here/';
$config['index_page'] = '';

Comments

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.