繁体   English   中英

在 url 中没有 index.php 时,codeigniter 无法工作

[英]codeigniter not working without index.php in url

我正在处理一个 codeigniter 项目,当我将它安装在数字海洋 ubuntu 液滴上时,我能够开箱即用地使用 codeigniter。 但是,当我加载我想使用的这个项目时,如果 url 中没有 index.php,项目就会中断并且我看到 404 错误:在此服务器上找不到请求的 URL。

在 domain.com/index.php/login 上有一个登录页面即使我登录时,它也会被重定向到 domain.com/dashboard 而没有 index.php

这是我的.htaccess:

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

这是我的 config.php:

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

奇怪的是,如果我将 /index.php/ 添加到 base_url 它可以工作,但不会加载 CSS / javascript 资源。 不知道为什么我面临这个错误。

您应该应用以下更改:

尝试将config.php uri_protocol替换为它,

//find this `index_page`
$config['index_page'] = "index.php"
// replace with it
$config['index_page'] = ""


//find this `uri_protocol`
$config['uri_protocol'] ="AUTO" 
// replace with it
$config['uri_protocol'] = "REQUEST_URI"

.htaccess

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

更多参考

检查 default.conf

在我的网站上,我使用/etc/apache2/sites-enabled/000-default.conf在您的网站上它可能是/default.conf

您需要添加这一行:

AllowOverride all

这是我的 conf 文件的样子:

VirtualHost *:80>
<Directory /var/www/html>
                AuthType Basic
                AuthName "Restricted Content"
                AuthUserFile /etc/apache2/.htpasswd
                Require valid-user
                Options +ExecCGI
                DirectoryIndex index.php
                AllowOverride all
        </Directory>
        DocumentRoot /var/www/html

然后重启apache: sudo service apache2 restart

缺少问号? 在 .htaccess 中的 index.php 之后,所以

 RewriteRule ^(.*)$ index.php/$1 [L,QSA]

这是正确的方法

 RewriteRule ^(.*)$ index.php?/$1 [L]

在 Linux 托管环境中,这通常是必需的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM