
- Views: 4.6K
- Category: Codeigniter
- Published at: 10 Feb, 2017
- Updated at: 18 Aug, 2023
How to remove index.php from URL in Codeigniter
How to remove index.php from the URL in Codeigniter?
If you are a beginner OR don't know how to remove index.php in Codeigniter 4 or Codeigniter 4..? I will show you how to remove index.php from the URL in CodeIgniter.
You know you consistently access your controllers and functions with index.php because, by default, index.php is included in your URLs.
www.yourdomain.com/index.php/controller/function
When You want a pretty URL for your website, you should remove index.php from your project; with index.php. My URL is like this www.xyz/index.php/courses, and without index.php, its looks like this www.xyz.com/courses.
In other words, it is a user-friendly URL
Open your config.php in your controller/config/config.php, now find
$config['index_page'] = "index.php" remove index.php
$config['index_page'] = ""
Now find
$config['uri_protocol'] ="AUTO" replace it $config['uri_protocol'] = "REQUEST_URI"
Now create a .htaccess file in your root directory.
Paste this code in your .htaccess file, which you just created.
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L,QSA]
[embed]https://www.youtube.com/watch?v=lPl2zmjNpl8[/embed]
- Tag
- .htaccess file
0 Comment(s)