我正在使用一个代码点火器项目,当我将其安装在数字海洋 ubuntu droplet 上时,我可以开箱即用地使用代码点火器。但是,当我加载我想要使用的这个项目时,如果 index.php 不在 url 中,项目会中断,我看到一个 404 错误:在此服务器上找不到请求的 URL。
有一个登录页面在 domain.com/index.php/login 即使我登录,它也会被重定向到没有索引的 domain.com/dashboard.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]
这是我的配置.php:
$config['index_page'] = '';
$config['base_url'] = 'http://my_really_cool_domain.com';
奇怪的是,如果我将/index.php/添加到它工作base_url,但 CSS/javascript 资源无法加载。不知道为什么我遇到此错误。
您应该应用如下更改:
尝试将uri_protocol
替换为config.php
,
//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>
更多参考
检查默认.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 托管环境中,这通常是必需的。