I've looked in the documentation of Codeigniter of removing the index.php
from the URL when accessing different views, the code shows how to remove it with apache:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
However, when I go to http://localhost/code/home
, I get this:
The requested URL /code/home was not found on this server.
But accessing http://localhost/code/index.php/home
works just fine, how come it isn't working for me?
I'm on a Mac OS X Snow Leopard using the Sites
directory: /Users/~myusername~/Sites/code
, and I'm not using any software, i.e. MAMP, XAMPP.
EDIT
For the sudo /usr/sbin/apachectl -k restart -S
command, I get this:
VirtualHost configuration:
wildcard NameVirtualHosts and _default_ servers:
*:80 is a NameVirtualHost
default server code.local (/private/etc/apache2/httpd.conf:146)
port 80 namevhost code.local (/private/etc/apache2/httpd.conf:146)
Syntax OK
To remove index.php from URL just add
in the .htaccess file and move the .htaccess file near to index.php location
in config.php in config folder set
You should change
to
You also need to modify the $config['index_page'] variable like this:
Please refer to my post at http://www.boxoft.net/2011/07/removing-index-php-from-codeigniter-2-0-2-url/ if you like.
in
/etc/apache2/users/.conf
try adding ..
and restart Apache to check results ..
You all uri parts are rewrited, so it points to /index.php/code/home. The and good way to do it is to setup mapping eg. http://code.local to point to your /Users/~myusername~/Sites/code, then all your requests are resolved on the root level and everything will work as it should.
EDIT: Downvoters seem to be ignorants, but nevermind..
Here's what your code does now:
So like I said before the GOOD way would be host mapping so you get everything on the root level (which is GOOD as most likely you will have it this way on the production serv...) and that will do the trick withour changes in .htaccess.
Otherwise you may use Francesco's advice with RewriteBase, but a bit changed:
so simply change the RewriteRule to this:
copy the .htaccess on your main codeigniter folder, mine was localhost/codeigniter/ and then change the {RewriteBase / to RewriteBase /codeigniter/}
Try this one
I tried 3 before I got one to work