【问题标题】:How to remove index.php from url using .htaccess on linux server in codeigniter?如何在codeigniter中使用Linux服务器上的.htaccess从url中删除index.php?
【发布时间】:2014-02-10 20:39:45
【问题描述】:

我的项目在本地成功运行但无法在我的服务器上运行我在 hostgator 中有一个 Linux 服务器托管

默认控制器工作正常,但例如:

example.com/contact-us 不工作,它将重定向到服务器的 404 页面未找到页面但 example.com/index.php/contact-us 工作

我的 .htaccess 代码是:

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

配置:

$config['base_url']     = 'http://linksture:2000/websitebusinessforsale.com/project';
$config['index_page']   = '';
$config['uri_protocol'] = 'REQUEST_URI';

不知道是什么问题,先谢谢你的回复

【问题讨论】:

标签: .htaccess codeigniter


【解决方案1】:

试试这个

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

【讨论】:

    【解决方案2】:

    您拥有的代码很可能位于 apache 根目录的文件夹中。如果是这样的话,你需要写

    /project/index.php/$0
    

    因此,如果您已将所有代码上传到 /var/www/myproject,请使用

    /myproject/index.php/$0
    

    【讨论】:

    • 我不明白你该写什么来代替 /project?
    【解决方案3】:

    我知道也许你找到了解决这个问题的方法, 问题出在 Apache 配置中。

    首先,找到配置文件,(在我的例子中,我使用 Linux Mint) 配置文件应该在/etc/apache2/sites-available/

    继续编辑default.conf文件(取决于你的机器,在我的机器上它命名为000-default.conf) 使用此命令编辑文件sudo gedit 000-default.conf

    将此命令放在虚拟标签之外

    <Directory /var/www/html>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
    </Directory>
    

    使用sudo service apache2 restart保存并重启你的apache

    因此,您必须在您的机器上找到 apache 配置文件,然后执行相同的步骤。

    【讨论】:

      猜你喜欢
      • 2014-11-25
      • 2017-05-20
      • 2018-09-17
      • 1970-01-01
      • 2015-12-29
      • 2014-01-07
      • 1970-01-01
      • 2023-03-16
      • 1970-01-01
      相关资源
      最近更新 更多