【问题标题】:How to remove index.php in codeigniter on ubuntu server?如何在 ubuntu 服务器上的 codeigniter 中删除 index.php?
【发布时间】:2014-01-07 15:26:01
【问题描述】:

我已经研究了有关 stackoverflow 的所有问题,以从 codeigniter 中删除 index.php,但我仍然无法做到。只有登录页面打开,但其余页面为空白。 我正在使用自己的ubuntu linux 服务器。 我的重写模块也打开了。我用所有可能的值尝试了$config['uri_protocol']AUTO, PATH_INFO, QUERY_STRING, ORIG_PATH_INFO。 我的 htaccess 代码在这里

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

vhost 文件在这里

DocumentRoot /home/black-sheep/black-sheep.org

    <Directory />
            Options FollowSymLinks
            AllowOverride FileInfo
    </Directory>

    <Directory /home/black-sheep/black-sheep.org/>
            Options +Indexes +FollowSymLinks +MultiViews
            AllowOverride All
            Order allow,deny
            allow from all
    </Directory>


    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
            AllowOverride None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
    </Directory>

    ErrorLog /var/log/apache2/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog /var/log/apache2/access.log combined

我的网址是

http://black-sheep.org/

这是我在 index.php 上回显 __FILE__ 时的路径

/home/black-sheep/black-sheep.org/index.php

令人惊讶的是,在没有 index.php 的同一台服务器上的 wordpress 站点在遵循 htaccess 的情况下运行良好。

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

我也尝试过使用这个 htaccess,但它对我不起作用。

请给我建议解决方案。 在此先感谢

【问题讨论】:

  • 是否启用了 mod_rewrite ?
  • 是的……我确定……

标签: php .htaccess codeigniter ubuntu


【解决方案1】:

我也有同样的问题。我修复它。 您必须在站点的根目录中添加 .htaccess 文件

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

而主你必须在 /etc/apache2/apache2.conf 中更改站点配置。
搜索 目录 /var/www/ 更改 AllowOverride None -> AllowOverride All

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

【讨论】:

  • 您的解决方案导致输出错误 500
【解决方案2】:
    How to remove index.php in localhost(Ubantu) using codeigniter

   sudo nano /etc/apache2/apache2.conf
    write this code below.

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

  within codeigniter framework config/config.php
  In application/config/config.php change:

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

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

 make .htaccess file main folder directory

<IfModule mod_rewrite.c>
  RewriteEngine On
 #RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^ index.php [QSA,L]
</IfModule>

【讨论】:

    【解决方案3】:

    试试这个解决方案。

    将下面的代码粘贴到 .htaccess 文件中并将其移动到您的 codeigniter 文件夹

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

    【讨论】:

    • 你在 config.php 的 $config['index_page'] 上添加的值是什么
    • CI 默认为 AUTO
    • 你能把它设为 $config['index_page'] == '' ;如果仍然存在问题,请告诉我
    【解决方案4】:

    我遇到了同样的问题,但能够纠正它。我正在给你完整的指导。一步一步来。。

    首先通过输入以下命令从终端检查 mod_rewrite 是否打开:

    sudo a2enmod rewrite
    

    然后打开位于下面提到的目录中的文件apache2.conf

    /etc/apache2/apache2.conf
    

    在文件中找到&lt;Directory /var/www/&gt;,将AllowOverride None改为AllowOverride All

    如果不允许您保存文件,则表示该目录没有所需的权限。所以请通过运行以下命令来给出它。

    sudo chmod -R 777 /etc/apache2/ 然后保存文件。

    现在编写您的.htaccess 文件并通过放置以下代码保存文件。

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

    然后通过以下命令重新启动你的 apache 服务

    sudo service apache2 restart
    

    希望,然后它会工作......

    【讨论】:

      猜你喜欢
      • 2014-11-25
      • 2013-09-04
      • 2018-01-27
      • 2015-03-11
      • 2019-08-31
      • 2014-02-10
      • 2013-05-09
      • 2021-10-05
      • 1970-01-01
      相关资源
      最近更新 更多