duanpin2009 2013-04-17 01:29
浏览 59
已采纳

无法从CodeIgniter中的URL中删除index.php

I have been pulling my hair out for three days, I have googled everything, been on the code igniter forums and checked stack overflow from top to bottom.

All i want to do is remove the index.php from the url's. The closest post I found to my problem was not answered: Post

If i go to localhost/CodeIgniter my main page is shown. if i click my links i get an error that the page does not exist.

404 Page Not Found

The page you requested was not found.

Based on everything i have read, here is my current configuration.

MAC OSX 10.8.3 MAMP CodeIgniter 2.1.3

My root directory is www/CodeIgniter/ Here is the .htaccess file that is in the CodeIgniter Root

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

Here is the config setup for CodeIgniter: I tried every setting for uri_protocol with no success

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

I verified that I have mod_rewrite enabled and that AllowOverride is set to All in httpd.conf.

****UPDATE so I deleted MAMP and codeigniter and started from scratch. Now with the .htaccess file below, when i go to localhost the codeigniter folder is not shown. If i try to browse to the folder I get the following error.

    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.

when i looked in the error log, i have the following error.

[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

I verified that I have mod_rewrite enabled in my phpinfo();

If i remove the .htaccess file I can browse to the folder and get the main page but of course the links don't work. Any suggestions would be greatly appreciated.

    <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>
  • 写回答

5条回答 默认 最新

  • donoworuq450547191 2013-07-20 01:47
    关注

    Better late than never but I had to modify my httpd.conf file, after like three restarts it just started working. Maybe this can help someone else

    <Directory />
        Options FollowSymLinks
        AllowOverride All
        Order deny,allow
        Deny from all
    </Directory>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题