ddiipp
ddiipp

Reputation: 205

How to get rid of index.php in codeigniter?

I was creating my first codeigniter project. I like this framework very much. But is there anyway to remove index.php page from the url ? Beside .htaccess ? Like i using form helper class to generate form. with this code

<?= form_open('site/login'); ?>

And the URL came out

<form action="http://localhost/index.php/site/login" method="post" accept-charset="utf-8">

It would be great if somebody share how to do it. Thanks

Upvotes: 0

Views: 1265

Answers (3)

Eldho NewAge
Eldho NewAge

Reputation: 1333

RewriteEngine on
RewriteBase /
# Hide the application and system directories by redirecting the request to 
index.php
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]

You may also refer the below links:

https://www.formget.com/codeigniter-htaccess-remove-index-php/

http://snipplr.com/view/5966/codeigniter-htaccess/

Upvotes: 0

John Corry
John Corry

Reputation: 1577

That won't remove it from the output of form_open().

If you use .htaccess to reroute the requests, make sure you also set the index_page in your config file to an empty string.

$config['index_page'] = '';

With my index_page config item set to '', the form_open() method doesn't put an index.php in the form action URL.

Upvotes: 1

Oliver Atkinson
Oliver Atkinson

Reputation: 8029

Its not possible without .htaccess, but why havent you got access to this? you can put it in the directory of the index.php to have your desired effect.

Because I don't like dead links, I will quote the official documentation:

Removing the index.php file

By default, the index.php file will be included in your URLs:

example.com/index.php/news/article/my_article You can easily remove this file by using a .htaccess file with some simple rules. Here is an example of such a file, using the "negative" method in which everything is redirected except the specified items:

 RewriteEngine on RewriteCond $1 !^(index\.php|images|robots\.txt)
 RewriteRule ^(.*)$ /index.php/$1 [L] In the above example, any HTTP
 request other than those for index.php, images, and robots.txt is
 treated as a request for your index.php file.

Upvotes: 1

Related Questions