【问题标题】:I can't remove the index.php from the CodeIgniter URL我无法从 CodeIgniter URL 中删除 index.php
【发布时间】:2023-03-25 07:20:01
【问题描述】:

我想从 CodeIgniter 的路径中删除 index.php。

我尝试将配置文件中 index_page 的值更改如下:

$config['index_page'] = '';

然后我尝试了所有这些 .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]

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

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

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

<Files "index.php">
AcceptPathInfo On
</Files>  

但它们都没有奏效。

我也尝试将 uri_protocol 更改为:

   $config['uri_protocol']  = 'ORIG_PATH_INFO';

但还是不行。

我该如何解决这个问题?

编辑:

我尝试了这段代码来检查 mod_rewrite 是否启用:

<?php
 if( ! function_exists('apache_get_modules') ){ phpinfo(); die; }
 $result = ' not available';
 if(in_array('mod_rewrite',apache_get_modules())) $result = 'available';

?>
<p><?php echo apache_get_version(),"</p><p>mod_rewrite $result"; ?></p>

我得到了这个结果:

Apache/2.2.22 (Ubuntu)

mod_rewrite 不可用

【问题讨论】:

  • 尝试将url协议设置为自动$config['uri_protocol'] = 'AUTO';
  • 您的 htaccess 看起来不错。您确定您的网络服务器支持 htaccess 并启用了 mod_rewrite 吗?
  • @jonijones 我已经这样做了,但同样的问题:/
  • @FabrícioMatté 请检查我对帖子所做的修改
  • 看看有没有帮助askubuntu.com/q/48362/107606

标签: php .htaccess codeigniter indexing


【解决方案1】:

我遇到了同样的问题..最后它使用了以下代码

只需遵循这些简单的步骤:

1.将以下代码保存到.htaccss文件中..
2.放在主项目文件夹(不是应用程序文件夹)
3. 将代码第 3 行的“/projectFolderName/”部分重命名为 您的项目文件夹名称。

然后你就完成了。刷新看看。

<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteBase /projectFolderName/ 

 RewriteCond %{REQUEST_URI} ^system.*
 RewriteRule ^(.*)$ /index.php?/$1 [L]

 RewriteCond %{REQUEST_URI} ^application.*
 RewriteRule ^(.*)$ /index.php?/$1 [L]

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

【讨论】:

    【解决方案2】:

    这对我有用。在您的 .htaccess 文件中写入:

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

    在你的 config.php 文件中:

    $config['uri_protocol'] = 'AUTO';  
    

    确保您的 htaccess 在您的根文件夹中,而不是在应用程序文件夹中。

    【讨论】:

      猜你喜欢
      • 2013-08-09
      • 2012-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-26
      • 1970-01-01
      • 2012-11-14
      • 2013-11-29
      相关资源
      最近更新 更多