我已经在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文件并尝试使用
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:
在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
尝试一下:
<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文件中
RewriteEngine开
RewriteCond%{REQUEST_FILENAME}!-f
RewriteCond%{REQUEST_FILENAME}!-d
RewriteRule ^(。*)$ index.php / $ 1 [L]
现在您无需index.php即可刷新您的URL,它将可以正常工作
对于使用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