【问题标题】:Site not working after removal of Index.php from urlstring?从 urlstring 中删除 Index.php 后网站无法正常工作?
【发布时间】:2011-10-03 15:25:05
【问题描述】:

在我的旧网址中是http://localhost/midas/index.php

我的网站正在使用带有 CodeIgniter 的 MVC 框架。

我在 Apache XAMPP 中激活了 mod_rewrite 并使用了以下 htaccess 代码:

 RewriteEngine on
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^(.*)$ /index.php/$1 [NC,R=301,L]

当我输入我的基本网址时,它很好,我的主页会加载:

基本网址 = http://localhost/midas/

但是,当我单击导航菜单或链接时,我会收到 404 object not found 错误消息。

Apache 错误信息:

[2011 年 7 月 12 日星期二 13:48:55] [错误] [客户端 127.0.0.1] 文件不存在:C:/xampp/htdocs/midas/site,引用者:http://localhost/midas/

有什么我需要改变的地方吗?

【问题讨论】:

    标签: php html codeigniter mod-rewrite


    【解决方案1】:

    编辑 /application/config/config.php 并更改

    $config['index_page'] = 'index.php';
    

    $config['index_page'] = '';
    



    此外,您需要在启用mod_rewrite 后重新启动 Apache。

    这是我与 CodeIgniter 一起使用的 .htaccess(已修改,因此它应该适合您):

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /midas/
    
        #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
        RewriteCond $1 !^(index\.php|images|css|robots\.txt)
        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>
    

    它应该在您的根目录中(即C:\xampp\htdocs\midas)。

    【讨论】:

    • 请参阅codeigniter.com/wiki/mod_rewrite(我从那里得到.htaccess)以供进一步参考。
    • 如果仍有问题,您可能还需要将$config['uri_protocol'] 从默认的AUTO 值更改为QUERY_STRINGREQUEST_URI
    • 您好,我使用了您的 htaccess 并将其放入 midas 目录。编辑 - 好的,当我单击网页上的按钮时,它现在会将我带到 xampp 服务器页面?
    • 好吧,我不知道我做了什么,但它现在可以工作了,但是当我点击我的主页按钮时,它会将我带到 xampp 服务器页面。
    • 好的,当我点击我的关于页面时,它也会将我带到 XAMPP 页面
    【解决方案2】:

    你可能需要在你的 htaccess 中设置一个 RewriteBase

    见:http://httpd.apache.org/docs/current/mod/mod_rewrite.html

    我的猜测是

    RewriteBase /midas
    

    (紧跟在RewriteEngine 之后)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-13
      • 2010-10-28
      • 1970-01-01
      • 2018-02-17
      • 2011-06-14
      • 2017-03-09
      • 2012-11-14
      • 1970-01-01
      相关资源
      最近更新 更多