Reputation: 918
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?
Upvotes: 7
Views: 22810
Reputation: 1131
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
Upvotes: 0
Reputation: 512
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]
Upvotes: 1
Reputation: 11
This works. Although, please make sure your mod_rewrite is enabled,
httpd.conf
file under the C:\wamp\bin\apache\apache2.4.9\conf
folder inside the Apache’s installation folder.#LoadModule rewrite_module modules/mod_rewrite.so
in the httpd.conf
file.You can do this easily by searching the keyword “mod_rewrite”.#
at the starting of the line, #
represents that line is commented.mod_rewrite
in the Loaded Module section while doing phpinfo()
.Upvotes: 1
Reputation: 11
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
Upvotes: -1
Reputation: 5813
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
Upvotes: 26
Reputation: 1006
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.
Upvotes: 3
Reputation: 15045
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.
Upvotes: 3