【问题标题】:CodeIgniter removing index.php from URL not working [duplicate]CodeIgniter 从 URL 中删除 index.php 不起作用 [重复]
【发布时间】:2018-07-12 17:49:06
【问题描述】:

您好,以下是我为从 URL 中删除 index.php 所做的更改

替换为$config['index_page'] = "index.php"

$config['index_page'] = ""

然后替换$config['uri_protocol'] ="AUTO"

$config['uri_protocol'] = "REQUEST_URI"

然后我在.htaccess 文件中添加了以下代码

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

但这不起作用。任何想法,有什么问题?

【问题讨论】:

标签: php .htaccess codeigniter


【解决方案1】:

您不必编辑 index.php,将内容 .htaccess 文件替换为:

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

【讨论】:

  • 如果它不起作用,请尝试将其放入项目的所有 htaccess 文件中:)
  • 谢谢,我已经尝试过了,但对我不起作用。我已经更新了 config.php 而不是 index.php.... 你的意思是“尝试把它放在你项目的所有 htaccess 文件中”
  • 在我的项目中,我可以访问应用程序文件夹之外和应用程序文件夹内部。为什么它不起作用?什么错误?
  • 规则有效,但我犯了一个愚蠢的错误。我只是错过了 .htaccess 文件名中的 .(dot):(
  • 对我也不起作用...只有注销才有这个问题
【解决方案2】:

请尝试使用以下代码。

RewriteEngine On
RewriteCond %{REQUEST_URI}::$1 ^(.*?/)(.*)::\2$
RewriteRule ^(.*)$ - [E=BASE:%1]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

【讨论】:

    【解决方案3】:

    我不知道,但我认为您需要做的最后一件事是在您的 Apache 上。 httpd.conf

    改变

    AllowOverride None
    

    AllowOverride All
    

    我也可以知道你的 .htaccess 在哪里吗?

    【讨论】:

      【解决方案4】:

      将 .htaccess 文件放在项目文件夹中,如下所示:

      htdocs/your_project/.htaccess

      试试这个 .htaccess 的新代码:

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

      不要尝试删除已在您的应用程序文件夹中的其他 .htaccess 文件。

      config.php的变化如下:

      $config['base_url'] = 'http://localhost/your_project_name/';
      $config['index_page'] = '';
      $config['uri_protocol'] = 'REQUEST_URI';
      

      不要使用:

      $config['uri_protocol'] ="AUTO"
      

      希望它能完美地为您服务。

      【讨论】:

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