问题
this questions was asked before and has had many responses. The problem is nothing i tried worked.
Background: i use MAMP and all of my web project are located under WebProjects which I relocated out of its standard location within the MAMP folder in Applications. so my structure is something like this:
Documents/WebProjects/GreatSite/Application/...
What happened so far: my understanding is that removing index.php can be done either through httpd.conf or .htaccess. anytime i touched httpd.conf, Apache refuses to start. I tried various edits to .htaccess including the one in codeigniter.com/wiki/mod-rewrite and the last one from a post on SO which is this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
this give me the following error when i access the site:
An Error Was Encountered
Unable to determine what should be displayed. A default route has not been specified in the routing file.
I have updated config.php to have $config['index_page'] = ''; and i have placed the .htaccess file in the GreatSite folder.
One other note, my CI system folder is up a level from GreatSite. Not sure if this has any impact. also, apache has the module loaded.
so, I'm hoping someone has successfully done this on MAMP and could provide direction specifically around the content of their .htaccess (or even httpd.conf), it's location and any other mods they had to make to get this going.
update
and trying to access a controller using http://localhost:8888/greatsite/account rewrites the url as http://localhost:8888/greatsite/account/index and gives 2 errors:
Message: Undefined index: scaffolding_trigger
Filename: libraries/Router.php
Line Number: 164
and
Message: Cannot modify header information - headers already sent by (output started at /Users/djeetee/Documents/DevProjects/system/libraries/Exceptions.php:166)
Filename: libraries/Session.php
Line Number: 662
hope this helps.
thanks
回答1:
.htaccess does not have to reside in the same folder as index.php. You can do
RewriteRule ^(.*)$ /codeigniter/index.php?/$1 [L]
for instance. Just make sure you have the correct RewriteBase and then correct path to your index.php and that the rewrite module is enabled in apache.
来源:https://stackoverflow.com/questions/4704257/removing-index-php-on-mamp