0

While using codeigniter, I am facing some difficulties. That's about the index.php file in URLs.

CodeIgniter serves all it's pages using index.php. So, our url's should look like following:

http://www.example.com/codeigniter/index.php/something

I want to remove the index.php from URLs by editing the config.php file and creating an .htaccess file. After changing the config from

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

to

$config['index_page'] = '';

I am able to run my project without the index.php just like this:

http://www.example.com/codeigniter/something

So now, that link is working - but it's also working with the index.php fragment. I can also see the components with the http://www.example.com/codeigniter/index.php/something address.

My .htaccess file is :

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

Now, I want to make my site only available without the index.php in my links. I don't want this site to run with the index.php file in the link. I want http://www.example.com/codeigniter/something to run perfectly and http://www.example.com/codeigniter/index.php/something not to run. How can I do this?

2
  • Can you paste your vhost configuration? Commented Oct 5, 2013 at 14:48
  • Sorry, what is vhost configuration? I am hosting my project in localhost with xampp Commented Oct 5, 2013 at 14:54

4 Answers 4

1

you can try adding the following in your .htaccess file

RewriteCond %{THE_REQUEST} codeigniter\/index\.php
RewriteRule codeigniter\/index\.php -[F]

Basically, this rule tells to return a forbidden response if the request contains codeigniter/index.php

Sign up to request clarification or add additional context in comments.

Comments

1

try this one

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

put the code in your root folder htaccess.Please let me know if you face any problem

Comments

0

Add this rule above the one that you already have:

RewriteCond %{THE_REQUEST} \ /codeigniter/index\.php([^\?\ ]*)
RewriteRule ^ /codeignighter/%1 [L,R=301]

And it'll redirect requests that have index.php in it to the URL without it.

Comments

0

You should add a ? after index.php, so it works in all hostings. This is my htaccess

RewriteEngine On
#RewriteBase /   maybe you don't need it, depends on the hosting
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt|humans\.txt|license\.txt|sitemap\.xml|assets)
RewriteRule ^(.*)$ index.php?/$1 [L]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.