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,670 points
857 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,880 points
3,505 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,880 points
6,454 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,010 points
1,211 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,880 points
2,241 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,420 points
246 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,050 points
725 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,420 points
444 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
1,600 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
359 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