【问题标题】:Removing the index.php is not working删除 index.php 不起作用
【发布时间】:2011-08-03 06:17:35
【问题描述】:

我有这个site,当你点击中心的 go 时,我会将它转到这个 url

 http://dev.posnation.com/welcome/redirect

这不是欢迎控制器和重定向操作的正确页面。正确的网址是

 http://dev.posnation.com/index.php/welcome/redirect

我的codeigniter结构是这样的

-rw-r--r--@  1 tamer  staff   225 Apr 11 13:09 .htaccess
drwxr-xr-x@ 18 tamer  staff   612 Apr  8 17:26 application
drwxr-xr-x  11 tamer  staff   374 Apr 11 09:46 css
drwxr-xr-x@  6 tamer  staff   204 Mar 24 14:20 graphics
drwxr-xr-x  17 tamer  staff   578 Apr 11 09:54 js
drwxr-xr-x@ 10 tamer  staff   340 Apr  7 12:20 system
drwxr-xr-x@ 16 tamer  staff   544 Apr  7 12:20 user_guide

与index.php一起出一个目录

我的 .htaccess 由这个组成

DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

任何想法

【问题讨论】:

    标签: php .htaccess url codeigniter mod-rewrite


    【解决方案1】:

    您在 RewriteCond 之后错过了一条 Rewrite 规则行。试试

    DirectoryIndex index.php
    RewriteEngine on
    RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
    

    【讨论】:

    • 仍然没有。也许它与我的 index.php 以及我的系统和应用程序文件夹所在的位置有关
    • 你是说你的 index.php 在一个目录之外吗?目录的名称是什么,或者您能说明一下您的意思吗?
    • 您是否已从配置文件 base_url 中删除了 index.php?
    • index.php 位于何处。如果是 1 个目录,请尝试 RewriteRule ^(.*)$ ../index.php/$1 [L]。如果没有,您可能需要将 index.php 移动到同一目录中。
    • 目录的名字是posnation,是的,它是一个目录
    【解决方案2】:

    Codeigniter Wiki 提供以下狙击:

    <IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /
    
        #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>
    

    在您的配置中,请相应地更改以下变量:

    config['uri_protocol'] = 'QUERY_STRING'; //set to QUERY_STRING
    

    $config['index_page'] = ""; //Remove index.php
    

    确保您的 Apache mod_rewrite 模块已加载(仅当上述引发 404 时)。

    http://codeigniter.com/wiki/mod_rewrite/ 上可能还有很多问题

    【讨论】:

    • 这会产生 site.com/index.php/controller/method 吗?
    • 这不起作用...可能与我的 index.php 以及我的系统和应用程序文件夹所在的位置有关
    • 这主要将uri重定向到index.php页面,确保在你的Routes中设置为AUTO,并从你的配置文件中的base_url中删除index.php,你的系统目录是server-侧面,这应该没有效果。
    • 它根本不工作是正确的页面dev.posnation.com/index.php/welcome/redirect如果你取出index.php如果失败
    • 你知道htaccess文件必须和index.php在同一个目录下才能生效!!
    【解决方案3】:

    它有时会混淆什么会起作用。尝试将此添加为最后一行

     RewriteRule ^(.*)$ ./index.php?$1 [L,QSA] 
    

    【讨论】:

      【解决方案4】:

      我遇到了类似的问题。确保你得到了正确的 RewriteRule。不同的方法也需要不同的方法来捕获变量。我见过两个,其中一个基本上将 $_GET 数组变量应用于示例中给出的 url 变量。

      RewriteRule ^(.*)$ ./index.php/$1 [L,QSA]
      
      RewriteRule ^(.*)$ ./index.php?url=$1 [L,QSA]
      

      你可以分别捕捉'm:

      echo $_SERVER['PATH_INFO'];
      
      echo $_GET['url'];
      

      CodeIgniter 使用 index.php?/$1 。这给我带来了麻烦。

      【讨论】:

        猜你喜欢
        • 2014-08-12
        • 2013-12-29
        • 2019-01-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-02-10
        • 2021-04-11
        • 1970-01-01
        相关资源
        最近更新 更多