0

How can I remove index.php so that the URL tricks CI has can be taken advantage of? When I removed 'index.php' it will through either a 404 error or a 403, even if the necessary class exists on the controllers.

Here's currently my .htaccess on the root:

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

Other CI specs on config.php:

$config['index_page'] = '';

$config['uri_protocol'] = 'AUTO';

The rewrite_module is enabled.

On httpd.conf:

<Directory />
Options FollowSymLinks
AllowOverride None
Order Allow,Deny
Allow from all
</Directory>

EDIT: To be clear, I can access the 'homepage' of my app (http://localhost/projectfolder). However, when I access a specific controller (http://localhost/projectfolder/admin), it won't work. But when an index.php is in between the host and the controller (http://localhost/projectfolder/index.php/admin), it works. I'm looking to resolve the 'index.php' in-between.

Raffy Alcoriza
  • 137
  • 1
  • 3
  • 13
  • 1
    You can't simply delete index.php as that bootstraps the CodeIgniter application/framework. Feel free to move it to another directory and point your docroot there though. – Wing Lian Feb 22 '13 at 16:40
  • This will help you: http://stackoverflow.com/questions/15017448/how-can-remove-index-php-from-url/15017916#15017916 – Rahul Chipad Feb 23 '13 at 05:45

4 Answers4

0

Please make sure that mod_rewrite is enabled. Also please try httpd.conf like this

<Directory /youdirectory path>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
</Directory>

Please also check CodeIgniter URL set up here

nicholasnet
  • 2,117
  • 2
  • 24
  • 46
0

Expanding on Wing Lian's comment:

You don't physically remove the index.php file. You're getting a 403 because directory listing is denied (and index.php does not exist), and a 404 on the controller/method urls because they don't physically exist.

Put the CodeIgniter index.php back where it belongs, and you should be fine. This line:

$config['index_page'] = '';

Is the important part of "removing" index.php. With this blank, CodeIgniter's url/uri helper functions will not put index.php in the urls.

See my answer on proper base_url for more info.

Community
  • 1
  • 1
Brendan
  • 4,565
  • 1
  • 24
  • 39
0

If you are working with localhost then your $_SERVER['DOCUMENT_ROOT'] will be upto your wamp or xampp folder. It will not contain your project folder name.

So if your project folder name is suppose "test" then you have to write your htaccess as below.

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

You have to add "test/" at the last line and you will not need to add index.php in URL. I hope this will work.

Yash Shah
  • 184
  • 6
0

After reading your question a few times, it finally made sense. I believe you need to add a RewriteBase like below:

RewriteEngine on
RewriteBase /projectfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Wing Lian
  • 2,387
  • 16
  • 14