7

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?

cryptic ツ
  • 14,653
  • 9
  • 49
  • 77
JunaidKirkire
  • 818
  • 1
  • 7
  • 16

7 Answers7

26

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
Hasib Hasan Arnab
  • 5,483
  • 3
  • 27
  • 43
3

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.

cryptic ツ
  • 14,653
  • 9
  • 49
  • 77
3

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.

ashiina
  • 976
  • 1
  • 7
  • 21
1

Use the following steps,
1. Create .htaccess file in the document root [myroot_folder/.htaccess].
2. open the config file in application/config/config.php and do the following

$config['index_page'] = '';

remove index.php from your base url
if it is $config['base_url']= 'http://localhost/myroot_folder/index.php';
change it to $config['base_url']= 'http://localhost/myroot_folder/';

Now open the .htaccess file and add the following code block

DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
Ahmed Syed
  • 1,197
  • 1
  • 16
  • 37
Sinha
  • 502
  • 4
  • 11
1

This works. Although, please make sure your mod_rewrite is enabled,

  1. Find the httpd.conf file under the C:\wamp\bin\apache\apache2.4.9\conf folder inside the Apache’s installation folder.
  2. Find the following line #LoadModule rewrite_module modules/mod_rewrite.so in the httpd.conf file.You can do this easily by searching the keyword “mod_rewrite”.
  3. Remove the # at the starting of the line, # represents that line is commented.
  4. Then restart the apache server.
  5. You can see now mod_rewrite in the Loaded Module section while doing phpinfo().
rth
  • 8,446
  • 4
  • 41
  • 70
0

1) Make .htaccess file and put this code.

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

2) Change:

 $config['index_page'] = ''; 
 remove index.php present in config.php file

3) Rewrite on from your server

Shree
  • 18,997
  • 28
  • 86
  • 133
Siddharth Shukla
  • 935
  • 14
  • 14
-1

If you have not worked all but that you did so, try this:

Change AllowOverride None to AllowOverride All in the virtual host file in /etc/apache2/sites-available/default

Details here

Community
  • 1
  • 1
Ana Hdez
  • 11
  • 2