I have a project in CodeIgniter that I am running on my local machine on LocalHost. I have to use http://localhost/projectname/index.php/controller/function
to run my APIs. I want to access the same URL but without including index.php
in the URL.
Earlier I had XAMPP installed and I was using its htdocs folder and everything was functioning as required. But now I have uninstalled it and manually set up Apache 2.4, PHP 8, and MySQL 8. After doing so, there is this issue.
I am new to both manually setting up servers and CodeIgniter. Please help me fix this and if possible give a reason why this happens, it will help me learn.
Add a .htaccess in the root directory and then add the following rules to the .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
Then find the following file in your application. File Path is application/config/config.php. In this file find below the code
$config['index_page'] = 'index.php';
Change that line as below.
$config['index_page'] = '';
Now try to open URLs without index.php.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.