1

我已经把头发拔了三天了,我用谷歌搜索了所有东西,上过代码点火器论坛,并从上到下检查了堆栈溢出。

我想要做的就是从 url 中删除 index.php。我发现的最接近我的问题的帖子没有得到回答: 帖子

如果我去localhost/CodeIgniter我的主页显示。如果我单击我的链接,我会收到该页面不存在的错误。

404 Page Not Found

The page you requested was not found.

根据我读过的所有内容,这是我当前的配置。

MAC OSX 10.8.3 MAMP CodeIgniter 2.1.3

我的根目录是 www/CodeIgniter/ 这是 CodeIgniter Root 中的 .htaccess 文件

#Deny from all
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /CodeIgniter/

    #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 %{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>

这是 CodeIgniter 的配置设置:我尝试了 uri_protocol 的所有设置,但没有成功

$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

我确认我已启用 mod_rewrite,并且 httpd.conf 中的 AllowOverride 设置为 All。

****更新所以我删除了 MAMP 和 codeigniter 并从头开始。现在使用下面的 .htaccess 文件,当我转到 localhost 时,不会显示 codeigniter 文件夹。如果我尝试浏览到该文件夹​​,我会收到以下错误。

    Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, you@example.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

当我查看错误日志时,出现以下错误。

[Mon Apr 22 21:42:51 2013] [alert] [client ::1] /Users/me/Dropbox/www/codeigniter/.htaccess: <IfModule takes one argument, Container for directives based on existance of specified modules

我确认我在 phpinfo(); 中启用了 mod_rewrite;

如果我删除 .htaccess 文件,我可以浏览到该文件夹​​并获取主页,但当然链接不起作用。任何建议将不胜感激。

    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /codeigniter/

    #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 %{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>
4

5 回答 5

0

仅出于测试目的备份您的 htaccess 文件,然后将其完全清除并粘贴:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

看看您是否可以无错误地浏览该网站。

于 2013-04-17T03:17:55.267 回答
0

嘿,你为什么不做一件事......下载这个代码点火器安装https://github.com/amitavroy/cleanplate然后检查这是否没有错误。你 mod_rewrite 应该在offcourse

于 2013-04-17T05:54:24.730 回答
0
DirectoryIndex index.php
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]


内部配置文件:

$config['index_page'] = 'index.php';
$config['uri_protocol'] = 'REQUEST_URI'; //or 'QUERY_STRING'
于 2013-04-17T20:21:36.817 回答
0

迟到总比没有好,但我不得不修改我的 httpd.conf 文件,在重启了 3 次之后它才开始工作。也许这可以帮助别人

<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Deny from all
</Directory>
于 2013-07-20T01:47:52.347 回答
0

只需将以下内容粘贴到您的 .htaccess 文件中即可

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /CodeIgniter/index.php/$1 [L]

设置 $config['index_page'] = ''; //config.php $config['uri_protocol'] = 'REQUEST_URI';//config.php

于 2016-12-05T22:27:54.653 回答