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 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥50 power BI 从Mysql服务器导入数据,但连接进去后显示表无数据
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签)
  • ¥50 sft下载大文阻塞卡死
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失
  • ¥15 springboot+vue 集成keycloak sso到阿里云
  • ¥15 win7系统进入桌面过一秒后突然黑屏