【问题标题】:Removing index.php - official guide not working (code igniter)删除 index.php - 官方指南不起作用(代码点火器)
【发布时间】:2013-11-25 09:50:30
【问题描述】:

我正在尝试删除 Code Igniter 的 url 中的 index.php。根据官方指南,我应该将以下代码添加到 .htaccess 文件中。

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

这不起作用。

所以我做了更多的搜索,有人说我应该删除索引页面上的默认配置,所以我在 config.php 文件中进行了更改:

$config['index_page'] = '';

它仍然无法正常工作。然后,在更多的搜索中,我发现了不同版本的代码,比如这个(只是一个例子,我已经尝试了很多版本)

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

我最初将代码放在根目录的 .htaccess 中,但由于它不起作用,我也尝试将其添加到其他目录的 .htaccess 中。但是,仍然无法正常工作。

我只是使用默认的欢迎页面进行测试,所以我确定不是编码的问题。即

http://localhost/projectFolder/CodeIgniter/welcome/

有人知道我错过了什么吗?

【问题讨论】:

    标签: codeigniter


    【解决方案1】:

    我假设 http://localhost/projectFolder/CodeIgniter/ 映射到的任何文件夹都是您的 docroot,并且 .htaccess 文件位于该目录中。

    如果是这样,那么您的代码是正确的 - 所以这是您的 apache 配置的问题。通过更改目录块 - AllowOverride All,确保您允许 .htaccess 文件。

    Take a look at this page for help doing that.

    【讨论】:

    • 这似乎是在正确的道路上,但由于我使用的是 Mac 和 XAMPP,所以该链接似乎不适用于我。你有Mac的版本吗? (我在谷歌上搜索,但似乎没有多大帮助)
    • 这里是 xampp for mac 上“what's where”的链接:apachefriends.org/en/xampp-macosx.html#876 -- 您需要编辑 /Applications/XAMPP/etc/httpd.conf 文件。如果您正在运行虚拟主机,那么您将编辑一个名为 vhosts.conf 的文件(应该在同一目录中或附近 - 可能在 sites-available 目录中)。
    【解决方案2】:

    我认为下面的代码应该适合你

    RewriteEngine on
    RewriteCond $1 !^(index\.php|css|js|public|themes|captcha|robots|documents|\.txt)
    RewriteRule ^(.*)$ /projectFolder/index.php/$1 [L]
    

    希望对你有所帮助。

    【讨论】:

      【解决方案3】:

      对配置文件进行此更改

       $config['base_url'] = 'http://localhost/projectname/';
       $config['index_page'] = '';
      

      然后在你的 .htaccess 中尝试

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

      还要确保您在 apache 配置中启用了 mod_rewrite

      .htaccess 文件应该在项目的根目录下,即在应用程序文件夹之外

      【讨论】:

      • 我已经在使用您发布的配置,并且尝试将脚本更改为您提供的配置,但仍然无法正常工作。我想这是 mod_rewrite 的事情。如何启用它? (我正在使用带有 XAMPP 的 Mac。)
      猜你喜欢
      • 2014-01-15
      • 2013-02-27
      • 1970-01-01
      • 2021-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多