【问题标题】:CodeIgniter .htaccess remove index.php on ServerCodeIgniter .htaccess 删除服务器上的 index.php
【发布时间】:2014-11-25 04:55:46
【问题描述】:

我知道这里有很多问题和答案,但我真的很困惑,我还无法解决我的问题。请帮忙!

我可以通过这个 url 轻松访问我的控制器:

http://www.example.com/new/index.php/welcome

但我无法通过此 URL 获取它: http://www.example.com/new/welcome

我在子目录“new”中配置我的 CodeIgniter 站点,在我的服务器上,我的目录结构是:

/  
   htdocs
       new

/(这是空的),htdocs(这是我的名为“new”的目录和 new(这是我的 codeIgniter 文件所在的确切文件夹。 我在这里对“/”和“htdocs”感到困惑,我认为这是我无法处理的事情,因为我的域 example.com 指向 htdocs,即如果我将 index.php 放在 htdocs 中,例如。 com 将加载 index.php。

我在“新”目录中的 .htaccess 文件是:

RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php/$1

在 config/config.php 中:

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

我已经为“Auto”、“REQUEST_URI”和“QUERY_STRING”等尝试了$config['uri_protocol']

使用此配置,我可以在本地主机中删除 index.php,但无法在服务器上修复它。请帮忙!!提前致谢。

【问题讨论】:

  • 看看这个页面htaccessredirect.net
  • 我忘记了:$config['index_page'] = '';不要留空格
  • 没有空格...伙计请帮帮我..我的服务器是fasthosts
  • 试试我的回复
  • 我已经尝试了您在回复中描述的所有步骤,但没有效果。

标签: php apache .htaccess codeigniter mod-rewrite


【解决方案1】:

尝试在htaccess的index.php后面加上?

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

【讨论】:

    【解决方案2】:

    这个对我有用

    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]
    

    确保从 appliation/config/config.php 中删除 index.php

    $config['index_page'] = '';
    

    【讨论】:

      【解决方案3】:

      此代码适用于我:

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

      还有config.php

      $config['index_page'] = '';
      

      【讨论】:

        【解决方案4】:

        如果您说它在 localhost 上运行,则可能是服务器问题。通过在视图代码中的某处写入phpinfo(); 检查服务器 mod_rewrite 是否已打开。如果它未开启且您没有权限,请联系您的主机管理员。

        【讨论】:

          【解决方案5】:

          将此代码放入new目录内的.htaccess文件中

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

          并且不要忘记从以下位置删除空格:

          $config['index_page'] = ' ';

          【讨论】:

          • 无效...同样的问题..您指定的上述行中没有空格。
          • 引号之间的空格 mate ' '
          • 不,没有空格。它是: $config['index_page'] = '';
          【解决方案6】:

          尝试更改

          $config['uri_protocol'] = 'PATH_INFO';`
          

          或更改重写规则以使用查询字符串:

          RewriteEngine On
          #RewriteBase /
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteRule (.*) index.php?$1
          

          然后将协议设置为查询字符串:

          $config['uri_protocol'] = 'QUERY_STRING';`
          

          【讨论】:

            【解决方案7】:

            尝试在 .htaccess 中使用此代码:

            <IfModule mod_rewrite.c>
            RewriteEngine on
            RewriteBase /
            RewriteCond $1 !^(index\.php|robots\.txt)
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d 
            RewriteRule ^(.*)$ index.php/$1 [L,QSA]
            </IfModule>
            

            【讨论】:

            • 抱歉,没有效果。同样的问题。
            • 尝试使用:RewriteBase /new。我希望这对你有用。
            • 再次无效。不知道怎么解决:\
            • 您是否对配置文件进行了任何更改?
            • 不,我刚刚下载了codeIgniter,安装在我的本地PC上,效果很好,然后我将它上传到服务器,现在我遇到了这个问题。
            猜你喜欢
            • 2016-04-15
            • 2019-04-06
            • 2016-05-13
            • 2015-03-09
            • 2015-03-11
            • 2023-03-16
            • 2018-01-27
            • 1970-01-01
            • 2012-08-15
            相关资源
            最近更新 更多