【问题标题】:Can't remove index.php when in codeigniter在 codeigniter 中无法删除 index.php
【发布时间】:2022-01-28 00:40:07
【问题描述】:

我刚刚安装了 codeigniter,所以如果我输入:

http://mysuperwebpage.comyr.com/projects/thebookshelf/index.php/welcome

它会按应有的方式显示所有内容。

但是我想去掉url中的这个index.php,这样你就可以访问欢迎控制器,而无需在/welcome之前输入index.phphttp://mysuperwebpage.comyr.com/projects/thebookshelf/welcome

所以我按照我在堆栈上的相同问题中找到的所有必要步骤进行操作。我试过的:

config.php:

$config['base_url'] = 'http://mysuperwebpage.comyr.com/projects/thebookshelf/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

.htaccess 位于根文件夹中的文件:http://mysuperwebpage.comyr.com/projects/thebookshelf/.htaccess

尝试 #1(不起作用)

.htaccess:

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

尝试 #2(不起作用)

.htaccess:

RewriteEngine on
RewriteBase /
# Hide the application and system directories by redirecting the request to index.php
RewriteRule ^(application|system|\.svn) index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]

尝试 #3(不起作用)

.htaccess:

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

我错过了什么或做错了什么?第一次使用.htaccess。

【问题讨论】:

    标签: .htaccess codeigniter


    【解决方案1】:

    确保您的 .htaccess 文件位于 文件夹下,而不是 应用程序 文件夹下。
    这是你可能没有注意的。

    【讨论】:

    • 几天我的头撞在墙上,结果解决方案非常明显.....谢谢
    【解决方案2】:

    根据CodeIgniter docs,这是一种方法:

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

    【讨论】:

    • 如果我把它放在 .htaccess 里面,它甚至不允许我进入http://mysuperwebpage.comyr.com/projects/thebookshelf/,但允许访问http://mysuperwebpage.comyr.com/projects/thebookshelf/index.php
    【解决方案3】:

    嗯,我在主持人的常见问题解答中找到了以下信息: On this page

    所以我要做的就是在所有内容之前添加以下行:

    RewriteBase /projects/thebookshelf/

    所以现在它看起来像这样:

    RewriteBase /projects/thebookshelf/
    
    Options +FollowSymLinks
    Options -Indexes
    DirectoryIndex index.php
    RewriteEngine on
    RewriteCond $1 !^(index\.php|resources|images|css|js|robots\.txt|favicon\.ico)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond ${REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
    

    我希望这对使用虚拟用户主目录路径的人有所帮助,就像我的情况一样。

    【讨论】:

    • 谢谢它也帮助了我
    【解决方案4】:

    这对我有用

    对于您的 .htaccess 文件(将其定位在根文件夹中)

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

    config.php

    $config['base_url'] = "";
    $config['index_page'] = "index.php";
    $config['uri_protocol'] = "AUTO";
    

    【讨论】:

      【解决方案5】:

      在 public_html 目录中打开 .htaccess 并更新以下脚本

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

      【讨论】:

        猜你喜欢
        • 2016-04-21
        • 1970-01-01
        • 2018-10-17
        • 2013-08-09
        • 2012-12-27
        • 1970-01-01
        • 1970-01-01
        • 2018-10-16
        • 2013-08-02
        相关资源
        最近更新 更多