从url中删除index.php在本地主机上工作,但在在线上不起作用


Removing index.php from url works on localhost and doesn't work online

我使用codeigniter在PHP项目上工作,我从URL本地删除了index.php,这里是我的。htaccess

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

当我在线上传项目时,路由根本不起作用,我需要用纯url而不是路由设置index.php !

例如,

不写index,我必须写 index.php/product_management_controller/index

如果我写index,它不工作,即使我更新路由包括index.php !!这意味着路线也不工作!

我当前的路线是$route['index'] = "product_management_controller/index";

这里是我在config.php文件中设置的一些东西:
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

解决方案是什么?

可以在本地正常工作!!

您的托管服务器将需要允许.htaccess文件,在您的Apache配置中,您需要添加:

AllowOverride All

到Apache配置。然后重启Apache服务器。

你也可以试试

Options +FollowSymLinks -MultiViews RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule .* index.php/$1 [PT,L]

有一个关于在codeigniter上从url中删除index.php的文档https://ellislab.com/codeigniter/user-guide/general/urls.html

顺便说一下,你是在godaddy共享服务器按照评论,你没有访问apache配置文件,但好消息是你不需要担心重写模式是默认为你。:)

相关文章: