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?

7 Answers 7

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
Sign up to request clarification or add additional context in comments.

4 Comments

I have been threw several blogs and post looking for this answer and you are the only one who had the correct answer for me as well as made it very clear on what to do. Thank you so much!
Thanks @Travis Michael Heller
I forgot to add $config['index_page'] = ' ';
Thank you for mentioning the "project root folder". I have struggled with figuring out where this .htaccess file should go. It's not like there is only one.
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.

1 Comment

Did the above but still not working. Is there some other place also that needs to be configured?
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.

3 Comments

Please correct me if I am wrong but shouldn't it be httpd.conf ? Also my httpd.conf file is empty.
Thanks for taking the time to answer my question. I appreciate it.
Sorry, my mistake... it's httpd.conf! I fixed my answer. I hope this solution helps.
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().

Comments

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]

Comments

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

Comments

-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

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.