.htaccess不适用于Mac OS上的CodeIgniter项目

时间:2014-07-31 14:55:35

标签: php apache .htaccess codeigniter mod-rewrite

前一段时间我的大部分项目都使用了CodeIgniter。我重新回到了事物的摇摆中并且遇到了一些障碍。我现在在Mac OSX Mavericks上开发并使用MAMP作为我的Apache服务器。一切似乎都运行正常,但我无法一直摆脱URL中的index.php。我已将.htaccess文件添加到项目的根目录中。这是文件:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /ez-recruits/

#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

ErrorDocument 404 /index.php
</IfModule> 

关于如何制作这些文件我并不是很了解我通常只是从CodeIgniters网站上获取这些文件。我在URL中没有index.php时遇到404错误,如果我手动输入,页面将正常加载。此外,我正在开发Firefox,我收到一个错误说&#34; Firefox无法理解地址&#34;没有URL中的index.php。我确实在Apache服务器上激活了mod_rewrite。我已经在索引页面的配置文件中删除了index.php,我已将base_url设置为

  

$ config [&#39; base_url&#39;] =&#39; localhost:8888 / ez-recruits&#39;;

我做了一些研究,发现更改httpd.conf文件帮助了其他人,所以我把它的一部分更改为:

<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Deny from all
</Directory>

但它没有改变。有人知道我可能做错了什么或者这只是一个Mac问题吗?此外,在所有这些配置中,我是否会与在Windows机器上开发的其他人一起努力开发?

提前致谢。

3 个答案:

答案 0 :(得分:1)

试试这个.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    #RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]


    </IfModule>

    <IfModule !mod_rewrite.c>
        # If we don't have mod_rewrite installed, all 404's
        # can be sent to index.php, and everything works as normal.
        # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>

此外,您可以将$config['base_url']留空,如果您在多个系统上工作,这会让生活更轻松。

希望这有帮助!

答案 1 :(得分:0)

您需要在config.php文件中使用base_urlindex_page

$config['base_url']     = 'http://yourlocalurl/';
$config['index_page'] = 'index.php';

答案 2 :(得分:-1)

确保在config/autoload.php

中加载了以下帮助程序
$autoload['helper'] = array('url','file');