【问题标题】:Remove index.php from codeigniter in xamp从 xampp 中的 codeigniter 中删除 index.php
【发布时间】:2012-03-26 01:32:26
【问题描述】:

我已经尝试了很多答案,但总是遇到好的 ol,404 恐怖墙。我在使用 xamp 堆栈的 Windows 7 上。 mod_rewrite 已启用。

我把htaccess文件放在了主“codeigniter”目录下,即有application、system和user_guide的目录。我应该把它放在应用程序目录下吗?有views/model/config/etc.的那个?

这是我当前的 .htaccess 文件:

RewriteEngine On

# Put your installation directory here:
# If your URL is www.example.com/, use /
# If your URL is www.example.com/site_folder/, use /site_folder/

RewriteBase /website/codeigniter/

# Do not enable rewriting for files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# For reuests that are not actual files or directories,
# Rewrite to index.php/URL
RewriteRule .* index.php/$0 [PT] 

访问http://localhost/website/codeigniter/index.php/welcome 有效 访问http://localhost/website/codeigniter/welcome 不会

我的 config.php 有

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

非常感谢任何帮助!

错误是:

Object not found!

The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.

Error 404

更新 哦,刚想查看apache日志,得到这个错误:

[Thu Mar 08 18:28:25 2012] [error] [client ::1] File does not exist: C:/xampp/htdocs/website/codeigniter/welcome

所以它似乎没有选择正确的 codeigniter 重定向?不确定?

【问题讨论】:

    标签: php .htaccess codeigniter xampp


    【解决方案1】:

    首先创建 .htacess 文件并将下面的代码粘贴到该文件中 重写引擎开启

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

    然后转到配置文件

    $config['index_page'] = 'index.php';
    

    改成

    $config['index_page'] = '';
    

    并享受

    【讨论】:

      【解决方案2】:

      试试这个:

      RewriteEngine on
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ index.php/$1 [L]
      $config['index_page'] = 'index.php';
      

      改成

      $config['index_page'] = '';
      

      【讨论】:

        【解决方案3】:

        你在 apache 中启用了 mod_rewrite 吗?

        【讨论】:

        • 为什么要评论一个 2 岁的答案?我已经将其标记为删除
        【解决方案4】:

        我一次又一次面临同样的错误,但经过一番研究,我找到了解决方案。

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

        重要的是,the project folder。就像我使用RewriteBase /Codeigniter_start/RewriteRule ^(.*)$ /Codeigniter_start/index.php/$1 [L,QSA]

        也像这样从配置文件 index_page 更改。

         $config['index_page'] = '';
        

        希望这会有所帮助。

        【讨论】:

          【解决方案5】:

          尝试将 htaccess 的最后一行更改为:

          RewriteRule .* index.php/$1 [L] 
          

          【讨论】:

            【解决方案6】:

            还可以尝试将配置文件中的请求方法从 AUTO 更改为 REQUEST_URI

            【讨论】:

              【解决方案7】:

              首先,在 XAMPP 中启用 apache 的“重写模块”

              如果您使用的是 XAMPP 或 WAMP 包,那么您将在以下位置找到该文件:

              {xampp_dir}/apache/conf/httpd.conf
              {wamp_dir}/apache/conf/httpd.conf
              

              找到以下行并删除“#”号。

              LoadModule rewrite_module modules/mod_rewrite.so
              

              其实我们可以通过XAMPP弹出菜单进行上层操作:Apache -> Apache Modules -> rewrite module,选中即可启用。

              其次,我们需要通过以下方式更改 htaccess:

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

              【讨论】:

                猜你喜欢
                • 2021-12-15
                • 2017-04-04
                • 1970-01-01
                • 1970-01-01
                • 2014-09-20
                • 1970-01-01
                • 2021-04-11
                • 2016-05-14
                • 2014-10-28
                相关资源
                最近更新 更多