CodeIgniter removing index php from url

0 votes

My current urls look like this [mysite]index.php/[rest of the slug].

I want to strip index.php from these urls.

mod_rewrite is enabled on my apache2 server. In config, $config['index_page'] = '';

My codeignitor root .htaccess file contains:-

RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule .* index.php/$0 [PT,L]

But yet, it fails to work. I would like to know where am I going wrong?

Feb 23, 2022 in PHP by Rahul
• 9,680 points
1,260 views

1 answer to this question.

0 votes

To solve your doubt, use the following lines:-

Open config.php and do following replaces

$config['index_page'] = "index.php"

to

$config['index_page'] = ""

In some cases the default setting for uri_protocol does not work properly. Just replace

$config['uri_protocol'] ="AUTO"

By

$config['uri_protocol'] = "REQUEST_URI"

For the .htaccess root file, use:-

RewriteEngine on 
RewriteCond $1 !^(index\.php|resources|robots\.txt) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Please remember that the .htaccess code varies depending on the hosting server. Do some hosting servers such as Godaddy need to use an extra ? This answer lies in the last line of the above code. The following line will be replaced with last line in applicable case:


// Replace last .htaccess line with this line RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
answered Feb 23, 2022 by Aditya
• 7,680 points

Related Questions In PHP

0 votes
1 answer

How to check if a file exists from a url using php?

Hello, You have to use CURL function does_url_exists($url) { ...READ MORE

answered Nov 3, 2020 in PHP by Niroj
• 82,840 points
4,104 views
0 votes
1 answer

How to save image from url with curl PHP?

Hello @kartik, try this: function grab_image($url,$saveto){ ...READ MORE

answered Nov 14, 2020 in PHP by Niroj
• 82,840 points
7,457 views
0 votes
0 answers

PHP CodeIgniter 4 - Form Submission - error "Can't find a route for 'registrations/index'"

The route is created in appConfigRoutes.php, and ...READ MORE

Aug 6, 2022 in PHP by Kithuzzz
• 38,000 points
1,700 views
0 votes
1 answer

How can we avoid my php form from hacking?

Hii @kartik, If you want to know php ...READ MORE

answered Feb 13, 2020 in PHP by Niroj
• 82,840 points
2,607 views
0 votes
1 answer
0 votes
1 answer

Ceon SEO URl gives the error page not found in zen cart

in the admin section there is  an ...READ MORE

answered Feb 18, 2022 in Others by narikkadan
• 63,600 points
443 views
0 votes
0 answers

SEO friendly url using php

I wanted to use php to make ...READ MORE

Feb 18, 2022 in Others by Kichu
• 19,040 points
963 views
0 votes
1 answer

Creating SEO friendly urls using htaccess

its just a simple step just use ...READ MORE

answered Feb 20, 2022 in Others by narikkadan
• 63,600 points
642 views
0 votes
1 answer

Convert a PHP object to an associative array

Start with simply typecasting the line:- $array = ...READ MORE

answered Feb 23, 2022 in PHP by Aditya
• 7,680 points
2,103 views
0 votes
1 answer

How do I convert a string to a number in PHP?

You don't have to do this, since ...READ MORE

answered Feb 23, 2022 in PHP by Aditya
• 7,680 points
606 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP