【问题标题】:CodeIgniter Removing index.php using .htaccess fileCodeIgniter 使用 .htaccess 文件删除 index.php
【发布时间】:2015-05-16 06:50:23
【问题描述】:

使用 .htaccess 文件在 CodeIgniter 中删除 index.php 对我不起作用。我尝试了以下代码,即使不起作用。

    <IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L,QSA]
</IfModule>

我试过这个http://firstcode.info/codeigniter-removing-index-php-from-url/。但不工作。但它在我的本地主机中工作。我还编辑了 httpd.config 文件。但是没有用。 请帮帮我。

【问题讨论】:

  • 找到了这个,github.com/riwakawebsitedesigns/htaccess_for_codeigniter 可能是使用完整的,有不同的 htaccess 供您试用。
  • 谢谢你我得到了解决方案
  • 在您学会阅读 apache 文件之前,请在 google 上搜索“far in space codeigniter htaccess”。您可能需要的最有用的示例,也是迄今为止我找到的最好的示例。

标签: php codeigniter


【解决方案1】:

你提到的代码是正确的。

您必须修改 apache2.conf(/etc/apache2/apache2.conf --- 它的我的服务器路径)检查您的路径。

找出这个罪魁祸首"AllowOverride None"/var/www//var/www/html

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>

更新到

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

别忘了sudo service apache2 restart

【讨论】:

  • /var/www/ 也很重要。这个工作目录的路径应该是正确的
  • 感谢您的回复我已经解决了
【解决方案2】:

第 1 步

打开文件夹“application/config”并打开文件“config.php“.config.php file.中找到并替换下面的代码

找到下面的代码

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

replace with the below code

$config['index_page'] = "

第 2 步

在 .htaccess 文件中编写以下代码

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

第 3 步

“application/config/config.php“,然后找到并替换下面的代码

找到下面的代码

$config['uri_protocol'] = "AUTO"

replace with the below code

$config['uri_protocol'] = "REQUEST_URI" 

【讨论】:

  • 我已经尝试了上面的代码我得到了内部服务器错误
  • 感谢您的回复我已经解决了
【解决方案3】:

试试这个代码

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php/$1 [L]

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

<IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php 
</IfModule>

在我的 config.php 文件中,我有以下设置。

$config['index_page']   = "";
$config['uri_protocol'] = "PATH_INFO";

【讨论】:

  • 感谢您的回复我已经解决了
【解决方案4】:

如果使用 localhost 或 domainname.com,请尝试在 config.php 中更改基本 url

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

$config['base_url'] = 'http://domainname.com/'; // domainname.com

【讨论】:

    【解决方案5】:

    添加.htacess

    RewriteEngine on
    RewriteCond $1 !^(index\.php|public|\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?$
    

    $config['index_page'] 中的config.php 中删除“index.php”(保留空白值)

    并修复项目文件夹的权限。

    【讨论】:

      猜你喜欢
      • 2013-03-07
      • 2019-04-06
      • 2016-05-13
      • 1970-01-01
      • 2012-08-15
      • 2015-03-09
      • 1970-01-01
      • 2018-12-04
      • 1970-01-01
      相关资源
      最近更新 更多