CodeIgniter删除URL中的index.php

问题描述 投票:0回答:5

我已经在codeigniter系统中创建了一个Ubuntu项目,并在base_url之后添加了以下内容。

http://192.168.1.123/project/

如果我访问任何其他URL,如下所示。

http://192.168.1.123/project/course/view/1

即重定向到“找不到页面”。如果在index.php之后加入base_url,则可以正常工作。

并且我如下创建了.htaccess文件。

RewriteEngine On
RewriteBase /project
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

config.php文件中

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

更改为

$config['index_page'] = '';

但仍然无法正常工作。请建议灵魂。这项工作将不胜感激。

.htaccess codeigniter codeigniter-2 codeigniter-url
5个回答
4
投票

更改.htaccess文件并尝试使用

RewriteEngine On
RewriteBase /project/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

3
投票

步骤1:

将其添加到htaccess文件中

<IfModule mod_rewrite.c>
  RewriteEngine On
  #RewriteBase /

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ index.php [QSA,L]
</IfModule>

步骤2:

在codeigniter配置中删除index.php

$config['base_url'] = ''; 
$config['index_page'] = '';

步骤3:

允许在Apache配置中覆盖htaccess(命令)

sudo nano /etc/apache2/apache2.conf

并编辑文件并更改为

AllowOverride All

对于www文件夹

第4步:

启用apache mod重写(命令)

sudo a2enmod rewrite

步骤5:

重新启动Apache(命令)

sudo /etc/init.d/apache2 restart

0
投票

尝试一下:

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

并且,在config.php中:

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

请确保已启用mod_rewrite模块


0
投票

首先将.htaccess文件放在应用程序文件夹之外。

然后将以下代码放入.htaccess文件中

RewriteEngine开

RewriteCond%{REQUEST_FILENAME}!-f

RewriteCond%{REQUEST_FILENAME}!-d

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

现在您无需index.php即可刷新您的URL,它将可以正常工作


0
投票

对于使用Linux的用户,这是要遵循的步骤

打开项目的根文件夹中的.htaccess文件。该文件夹与application文件夹位于同一文件夹。

将.htaccess的内容编辑为

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

打开配置文件并更改

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

$config['index_page'] = '';

导航到etc / apache2并打开一个名为apache2.conf]的文件夹

如下所示,将AllowOverride

None编辑为All”>
<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted

</Directory>

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

</Directory>

打开终端并运行此命令

sudo a2enmod rewrite

要激活新配置,请使用此命令重新启动apache

systemctl restart apache2

您现在已经成功从网址中删除了index.php

© www.soinside.com 2019 - 2024. All rights reserved.