CodeIgniter Forums
Removing the index.php file - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: Removing the index.php file (/thread-12297.html)

Pages: 1 2


Removing the index.php file - El Forum - 10-14-2008

[eluser]asim111[/eluser]
Hi, i am new to CI.
i have been developed an "auto dealer" module by using CI.

i want to remove index.php from the URL...
Todo this, i created a .htaccess file
Code:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
    RewriteEngine on    
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteRule ^(.*)$ http://www.auto_site_url.co.uk/index.php/$1 [L]
</IfModule>

secondly,i modified config file
Code:
$config['index_page'] = "index.php";
Replaced with
Code:
$config['index_page'] = "";


this project is working 100% on local server.
but on live server it is not working properly


ON LIVE SERVER its automatically changing site url like
Code:
http://www.auto_site_url.co.uk/
INTO
Code:
http://www.auto_site_url.co.uk/index.php/


and due to this, displaying error page with message
Code:
An Error Was Encountered
Unable to load the requested class: my_validator

i think something wrong with .htaccess file, but not sure

please help me to resolve this issue

thanks


Removing the index.php file - El Forum - 10-14-2008

[eluser]Flemming[/eluser]
Hi Asim,

if you remove the mod_rewrite rules and replace $config['index_page'] = "index.php"; in your config file, does the site work properly?

If it does then you know for sure that the problem is with your mod_rewrite - although it looks fine to me. If it doesn't ... then there is a problem elsewhere!

HTH


Removing the index.php file - El Forum - 10-14-2008

[eluser]asim111[/eluser]
Hi,
i tried with index.php....
it is working

on other hand, i resolved this error

Code:
An Error Was Encountered
Unable to load the requested class: my_validator


i created my custom library called MY_Validator.php and my live server is linux based.
on linux filenames are case sensitives. i renamed MY_Validator.php file to my_validator.php

now its look ok to me.



but now problem is:

i can visit my site without any error by using

Code:
http://www.mysite.co.uk/index.php/used-cars/

but i like to access like

Code:
http://www.mysite.co.uk/used-cars/


more intresting thing. it automatically adding index.php

if i will type http://www.mysite.co.uk/used-cars/
it will automatically convert url to
Code:
http://www.mysite.co.uk/index.php/used-cars/

and i can see perfect page...


any idea bro...?


Removing the index.php file - El Forum - 10-14-2008

[eluser]Flemming[/eluser]
It must be getting the 'index.php' from your config file! Check you have this set correctly :

$config['index_page'] = "";

If in doubt, try putting this in your config :

$config['index_page'] = "foobar.php";

See what happens - if you find that your urls are being rewritten now with foobar.php on the end then it's clearly coming from your config.php!

HTH


Removing the index.php file - El Forum - 10-14-2008

[eluser]asim111[/eluser]
Hi again!

i tried to change config file nothing happened.

but when i changed .htaccess file to index.php to foo.php

Code:
RewriteRule ^(.*)$ http://www.mysite.co.uk/foo.php/$1 [L]

i typed in browser:
Code:
http://www.mysite.co.uk/used-cars/
and url automatically converted into
Code:
http://www.mysite.co.uk/foo.php/foo.php/foo.php/foo.php/foo.php/foo.php/foo.php/foo.php/foo.php/foo.php/foo.php/foo.php/foo.php/foo.php/foo.php/foo.php/foo.php/foo.php/foo.php/foo.php/used-cars/

My route file is like:
Code:
$route['default_controller'] = "main";
$route['used-cars'] = "main/used_cars";

I think logical error some where... but why it is working fine on my local machine. urls & everything


Removing the index.php file - El Forum - 10-14-2008

[eluser]Flemming[/eluser]
It doesn't make any sense!

if you STOP using the .htaccess rewrite (ie. as initial installation) and put

Code:
$config[‘index_page’] = ”index.php“;
back in your config.php

then you should be able to visit

Code:
http://www.mysite.co.uk/index.php/used-cars/


and it should work fine?

???


Removing the index.php file - El Forum - 10-14-2008

[eluser]asim111[/eluser]
Now my .htaccess file is blank
and added index.php into config.php file

I can access my site
Code:
http://www.mysite.co.uk/index.php/used-cars/

But error with this
Code:
http://www.mysite.co.uk/used-cars/

Error is
Code:
Page not found
The page you are looking for might have been removed,
had its name changed, or is temporarily unavailable.



Removing the index.php file - El Forum - 10-14-2008

[eluser]Flemming[/eluser]
Excellent! So it is working as expected now! :-)

because you can access your site without any problems at
Code:
http://www.mysite.co.uk/index.php/used-cars/
this means the problem was definitely with your .htaccess and mod_rewrite rules.

I would suggest you post your entire .htaccess file so we can take a look. However - the .htaccess / mod_rewrite is an apache specific feature, NOT a codeIgniter feature so there is not a 100% guaranteed solution to making it work.

You can try searching the forum for .htaccess and mod_rewrite help / examples ?

Post your .htaccess here as well and I'll take another look at it!


Removing the index.php file - El Forum - 10-14-2008

[eluser]asim111[/eluser]
my simple .htaccess file

Code:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
    RewriteEngine on    
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteRule ^(.*)$ http://www.live-site-url.co.uk/index.php/$1 [L]
</IfModule>

thank you for help...


Removing the index.php file - El Forum - 10-15-2008

[eluser]Flemming[/eluser]
It looks ok to me but here's the one I use if you want to give it a try, for comparrison ...

Code:
RewriteRule ^/(index\.php|robots\.txt|favicon\.ico).*$ - [s=1]
RewriteRule ^/(.*)$ /index.php/$1

let me know what happens!