【问题标题】:How to remove index.php in Wamp?如何在 Wamp 中删除 index.php?
【发布时间】:2013-08-15 01:10:12
【问题描述】:

我一直在 XAMPP 中使用 CodeIgniter。 重定向到函数 URL 没有问题(例如,function1):

http://localhost/function1

当我更改为 WAMP 时,我遇到了问题。我无法重定向到 function1。但是,function1 仍可在以下位置访问:

http://localhost/index.php/function1

如何配置 WAMP 和 CodeIgniter 来删除 index.php? 为了我可以在使用 XAMPP 运行时运行 function1

谢谢。

【问题讨论】:

标签: codeigniter wamp


【解决方案1】:

请尝试以下方法:

1) 与应用程序文件夹并行创建 .htaccess 文件,然后复制粘贴以下代码:

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

2) 在应用程序文件夹中将$config['index_page'] 中的config.php 更改为空白,如下所示:

$config['index_page'] = '';

3) 启用 apache 的“rewrite_module”。点击 WAMP 符号 -> Apache -> Apache 模块 -> rewrite_module

现在您可以在 url 中没有 index.php 的情况下访问您的网站。

【讨论】:

    【解决方案2】:

    如果您还没有.htaccess 文件,请创建一个文件并在其中添加以下代码:

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

    确保将其放在与 index.php 相同的目录中。

    【讨论】:

      【解决方案3】:

      只需三个步骤即可在 WAMP 环境中的 Codeigniter 中从 url 中删除 index.php。

      1) 与应用程序持有者并行创建 .htacess 文件,然后复制以下代码:

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

      2) 在应用程序文件夹的config.php 中将$config['index_page'] 更改为空白,如下所示:

      $config['index_page'] = '';
      

      3) 启用 apache 的“rewrite_module”。

      重新启动您的 apache 并完成。

      详情:http://sforsuresh.in/removing-index-php-from-url-of-codeigniter-in-wamp/

      【讨论】:

        【解决方案4】:

        CodeIgniter 官方文档http://ellislab.com/codeigniter/user-guide/general/urls.html 中建议的 mod_rewrite 规则是

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

        在 WAMP 上非常适合我

        这也可以:

        <IfModule mod_rewrite.c>
        
            Options +FollowSymLinks
            RewriteEngine on
        
            # Send request via index.php
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteCond %{REQUEST_FILENAME} !-d
            RewriteRule ^(.*)$ index.php?/$1 [L]
        </IfModule>
        

        在这两种变体中,唯一的区别是条件。基本上,重要的是重写规则。条件可能取决于您的要求。

        这两个都不适用于我之前在 WAMP 上的工作。但是,问题出在 Apache 设置中。 rewrite_module 未启用。因此,请检查是否已启用。您可以使用 phpinfo() 来检查它是否启用,并检查 Loaded modules 列表。

        如果您没有启用它,您可以使用 WAMPserver 管理器启用它(从任务栏访问它)转到 Apache>Apache 模块并检查“rewrite_module”

        打开 httpd.conf 并检查 LoadModule rewrite_module modules/mod_rewrite.so 是否未注释。

        您必须重新启动 WAMPserver 才能激活更改。

        【讨论】:

        • 第二个解决方案在我安装的 CI 2.2.0 的 WAMP 上完美运行。只需将其复制到我的 .htaccess 即可立即使用。似乎没有我喜欢的 RewriteBase 也可以工作。
        猜你喜欢
        • 2016-10-09
        • 2018-03-02
        • 2011-10-28
        • 2012-06-11
        • 2014-08-19
        • 2015-10-27
        • 1970-01-01
        • 2011-01-18
        • 1970-01-01
        相关资源
        最近更新 更多