代码点火器 删除 URL 中的索引.php



我在系统中创建了一个codeigniter项目Ubuntu并添加了以下base_url,如下所示。

http://192.168.1.123/project/

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

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

这将重定向到"找不到页面"。如果我在base_url之后包括index.php,它工作正常。

我按如下方式创建了.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文件并尝试一下

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

步骤 1 :

在 htaccess 文件中添加此内容

<IfModule mod_rewrite.c>
  RewriteEngine On
  #RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ index.php [QSA,L]
</IfModule>

步骤 2 :

删除索引.php在代码点火器配置中

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

第 3 步 :

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

sudo nano /etc/apache2/apache2.conf

编辑文件并更改为

AllowOverride All

对于万维网文件夹

第 4 步 :

启用 apache mod rewrite (命令(

sudo a2enmod rewrite

步骤 5 :

重新启动 Apache (命令(

sudo /etc/init.d/apache2 restart

试试这个:

<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模块

首先将

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

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

重写引擎打开

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

重写规则 ^(.*($ 索引.php/$1 [L]

现在您可以在没有索引的情况下刷新您的 url.php它肯定会起作用

对于那些使用Linux的人来说,这是要遵循的步骤

在项目的根文件夹中打开 .htaccess 文件。它与应用程序文件夹位于同一文件夹中。

编辑 .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文件夹

允许覆盖从">"编辑为"全部",如下所示

<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

您现在已成功从网址中删除索引.php

最新更新