I want to access my URL\'s without index.php
in CodeIgniter. Here is my Blog
controller
class Blog extends CI_Controller {
pub
Enable mod_rewrite restart your apache server and in your .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
I just now struggled with this part again, even after being used to Codeigniter for 2+ years.
None of the answers helped me exactly, including the official Codeigniter's page about this, so I'm posting the solution that worked for me.
Enable Rewrite engine
sudo a2enmod rewrite
Change Apache's config file to allow folders to allow overriding of default security setting
sudo nano /etc/apache2/apache2.conf
Under the "Directory" options depending on the location of your files, edit
AllowOverride None
to
AllowOverride All
e.g.: My server files are in "/var/www", so my final result for corresponding Directory options is:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
In the file, put the following:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
In config/config.php file, change:
$config['index_page'] = 'index.php';
to
$config['index_page'] = '';
Restart apache2:
sudo service apache2 restart
Enjoy!
Please change your base_url path which exist in application/config
$config['base_url'] ='localhost/projectname/index.php'
to
$config['base_url'] ='localhost/projectname/'
Step:-1 Open the folder “application/config”
and open the file “config.php“
. find and replace the below code in config.php
file.
//find the below code
$config['index_page'] = "index.php"
//replace with the below code
$config['index_page'] = ""
Step:-2 Write below code in .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Step:-3 In some case the default setting for uri_protocol does not work properly. To solve this problem just open the file “application/config/config.php“
, then find and replace the below code
//find the below code
$config['uri_protocol'] = "AUTO"
//replace with the below code
$config['uri_protocol'] = "REQUEST_URI"
My Codeigniter version is 3.1.11 I'm trying all types of code in htaccess but that does not work then I was found this code.
Place the .htaccess file in the project folder like this: htdocs/your_project/.htaccess Try this new code for .htaccess:
RewriteEngine on
RewriteBase /your-project-directory-name/
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
How to removed index.php from url has been asked so many times, It is the same as what is for codeigniter 2 and 3.
For Xampp With Codeigniter Windows
Find application/config/config.php
Replace This
$config['base_url'] = "";
With This
$config['base_url'] = "your-project-url";
Replace This
$config['index_page'] = "index.php"
With This
$config['index_page'] = ""
In main directory create file called .htaccess
I use code below works fine for me in xampp in windows. More htacces here
Options +FollowSymLinks
Options -Indexes
<FilesMatch "(?i)((\.tpl|\.ini|\.log|(?<!robots)\.txt))">
Order deny,allow
Deny from all
</FilesMatch>
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Note: make sure your controllers are like example Welcome.php instead of welcome.php also you might need to create new routes in your route.php if remove index.php