CodeIgniter Forums
how do you really remove index.php - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: how do you really remove index.php (/showthread.php?tid=30077)

Pages: 1 2


how do you really remove index.php - El Forum - 05-02-2010

[eluser]bpdp[/eluser]
Okay so I've been at it for several days now and I just can't seem to remove the index.php from my urls.

• mod_rewrite is enabled
• apache has been configured to allow .htaccess overrides (other 301 redirects are working)
• $config['index_page'] = "";
• $config['uri_protocol'] = "AUTO"; (I have tried with other settings)
• I followed these instructions to setup my .htaccess file.

I am assuming that my issue is a path issue. I have the default CI install inside a project folder so my structure looks like this:
- localhost
- freelance
- ps
.htaccess
index.php
- system

any insight would be helpful, thank you!


how do you really remove index.php - El Forum - 05-02-2010

[eluser]tomcode[/eluser]
1. You might need to set the rewrite base
Code:
RewriteEngine on
RewriteBase /freelance/ps/
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

2. You might need to adapt the rewrite condition, in the CI example everything that is not named index.php, images or robots.txt is redirected to to the application, so if You have say a folder assets instead of images Your condition is

Code:
# ...
RewriteCond $1 !^(index\.php|assets|robots\.txt)
# ...



how do you really remove index.php - El Forum - 05-02-2010

[eluser]bpdp[/eluser]
Thanks for you reply tomcode. I had tried using the rewrite base before with no luck and unfortunately that is still the case. I get no error... it just doesn't work. Thanks for the tip in #2 though. I'm not trying to access anything special I just want my url to look like: http://localhost/freelance/ps/home/ instead of: http://localhost/freelance/ps/index.php/home/

this is so frustrating, I've been trying to get this to work for a couple days now and the mod_rewrite docs are a little over my head. seems like it should be easy.

my current (non-working) file looks like this:
Code:
RewriteEngine on
RewriteBase /freelance/ps/
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

Anything that I might be missing?


how do you really remove index.php - El Forum - 05-02-2010

[eluser]tomcode[/eluser]
just to make sure, http://localhost/freelance/ps/index.php/home/without use of .htaccess works ?

Then, what error do You get when using the .htaccess ?


how do you really remove index.php - El Forum - 05-02-2010

[eluser]bpdp[/eluser]
http://localhost/freelance/ps/index.php/home/
works with or without the .htaccess file

with .htaccess
http://localhost/freelance/ps/home/
throws a 404 (The requested URL /index.php/home was not found on this server.)

without .htaccess
http://localhost/freelance/ps/home
throws a 404 (The requested URL /freelance/ps/home was not found on this server.)

http://localhost/freelance/ps/index.php and http://localhost/freelance/ps/ both seem to work and are pointing to my default controller.


how do you really remove index.php - El Forum - 05-02-2010

[eluser]zhjx922[/eluser]
这个原理我不懂...嘿嘿


how do you really remove index.php - El Forum - 05-03-2010

[eluser]tomcode[/eluser]
Your Rewrite script works, but it points to http://localhost/index.php/home

Try without the line RewriteBase (haven't You started like that ?)

Do You use any symbolic links ? Try using the line
Code:
Options +FollowSymLinks

If it's not one of the above I cannot think of something else.


how do you really remove index.php - El Forum - 05-03-2010

[eluser]danmontgomery[/eluser]
Don't remove rewritebase, remove the leading slash in the rewriterule. The example htaccess assumes CI is installed in webroot (hence the lack of a rewritebase).

Code:
RewriteEngine on
RewriteBase /freelance/ps/
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [PT,L]



how do you really remove index.php - El Forum - 05-03-2010

[eluser]tomcode[/eluser]
Thanks noctrum, yeah, that should it be.


how do you really remove index.php - El Forum - 05-03-2010

[eluser]bpdp[/eluser]
YES!! it was the leading slash. A big thank you to the both of you. :-)