Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot remove index.php from CodeIgniter URL

My directory structure is /var/www/CI/ with all the folders viz., application, system under the folder CI. Have created a .htaccess file under CI.

Following is the code in .htacess.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Still localhost/CI/blog gives 404 error. Can anyone guide as to where this rule is wrong?

like image 815
JunaidKirkire Avatar asked Jan 12 '13 20:01

JunaidKirkire


3 Answers

Please try the following

At first, make sure you set the config file like the following..

$config['index_page'] = '';

Also make sure that mod_rewrite is enabled in the httpd.conf file and after that, overwrite your .htaccess file which is located your project root folder not in the application folder with the following code..

RewriteEngine on
RewriteCond $1 !^(index\.php|public|\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
like image 106
Hasib Tarafder Avatar answered Oct 20 '22 06:10

Hasib Tarafder


Make sure in your application/config/config.php file this is set as follows:

$config['index_page'] = '';

Also do this:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond $1 !^CI/(index\.php|public|images|robots\.txt|css)
    RewriteRule ^CI/(.*)$ CI/index.php/$1 [L]
</IfModule>

Typically you don't put CI in its own directory and put application and system in the root folder.

like image 23
cryptic ツ Avatar answered Oct 20 '22 06:10

cryptic ツ


Check your Apache configuration so that it is allowing an override. If the AllowOverride is set to None, the rewrite won't work for you.

Adding the following to your httpd.conf (NOT your .htaccess) should fix your problem

<Directory "/">
    AllowOverride All
</Directory>

Let me know if it's still not working.

like image 44
ashiina Avatar answered Oct 20 '22 04:10

ashiina