Cannot remove index.php from urls using Codeigniter on MAC OSX

微笑、不失礼 提交于 2021-01-28 05:47:50

问题


I just bought a Mac-pro with Mavericks 10.9.1 and before that I was working on pc with Windows 7.

I created a project under the windows 7 OS and now I want to import it to OSX, the import was successful apart from the .htaccess file. I can't remove index.php from my urls. I have MAMP installed and my urls only work if I use index.php:

  • don't work : (localhost/~username/feel/products)
  • work : (localhost/~username/feel/index.php/products)

I tried all the options of RewriteEngine, RewriteCond and RewriteRule in .htaccess file. I give all the folders/files chmod 755, have put $config['base_url']='' and $config['index_page'] = ''; with and without root or index.php page.

The file .htaccess is in the same folder of the index.php page, the AllowOverride None is AllowOverride All.


回答1:


I think the problem is related to the way OS X handles different users for apache. I used the .htaccess file as described in the CodeIgniter URL documentation and added a line using RewriteBase.

RewriteEngine on
RewriteBase /~username/path/to/CI/
RewriteCond $1 !^(index\.php|static|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

By the way, I'm using OS X 10.9.3 (Mavericks) and CodeIgniter 2.2.0




回答2:


You have to set AllowOverride All in the Directory:

/private/etc/apache2/httpd.conf

182 <Directory />
183     Options +FollowSymLinks
184     AllowOverride All
185     Order deny,allow
186     Deny from all
187 </Directory>

then restart Apache

sudo apachectl restart


来源:https://stackoverflow.com/questions/21888077/cannot-remove-index-php-from-urls-using-codeigniter-on-mac-osx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!