0

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

ddiipp
  • 203
  • 3
  • 15
  • 4
    RTM http://ellislab.com/codeigniter/user-guide/general/urls.html – Orangepill Sep 05 '13 at 19:42
  • No it isn't possible without htaccess. Everything is routed through the index.php file. Without it, you can't use codeigniter. So it's not possible without url rewriting. –  Sep 05 '13 at 19:43
  • possible duplicate of [How to remove "index.php" in codeigniter's path](http://stackoverflow.com/questions/1445385/how-to-remove-index-php-in-codeigniters-path) – M Khalid Junaid Sep 05 '13 at 19:44

3 Answers3

1

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.
Oliver Atkinson
  • 7,647
  • 29
  • 41
  • 1
    I don't think this is the answer to the question that was asked. – John Corry Sep 05 '13 at 21:01
  • @jcorry the answer is that it is not possible without the use of .htaccess, you are unable to rewrite a users url path and map it to a different url structure without it. – Oliver Atkinson Sep 05 '13 at 21:12
  • that's great, and a necessary PART of removing index.php from the URLs in the site...but the original question points to the URL produced in the action attribute of the form tag written by form_open(). There's no .htaccess trick that will cause form_open() to remove the index.php from the URLs it writes. For that, you must change the index_page item in the config array. – John Corry Sep 05 '13 at 21:15
1

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.

John Corry
  • 1,461
  • 13
  • 15
0
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/

Eldho NewAge
  • 1,143
  • 1
  • 11
  • 17