如何删除 URL 中的 index.php

我尝试删除 Codeigniter 中的索引页


第一步我这样做 //旧代码


$config['index_page'] = "index.php”

//新更新的代码(只需要删除 index.php )


$config['index_page'] = ""

然后对于第二步,我在 codigniter 的根目录中执行此创建文件 .htaccess 然后放入此代码源


RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

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

但这是同样的问题,我无法刷新网页


带有索引页面的 URL 工作:http://localhost:8089/codeigniter3/index.php/Hello/dispdata 但没有索引页面不起作用http://localhost:8089/codeigniter3/Hello/dispdata


您好是控制器,最后感谢您的帮助,:)


一只萌萌小番薯
浏览 220回答 5
5回答

慕的地10843

问题是,你把它安装在/codeigniter3/这应该解决它:// remove index.php$config['index_page'] = ""// Allow installation in a subfolder of your webroot$config['uri_protocol'] = "REQUEST_URI"并保留您的重写设置,它们没问题。

侃侃无极

Codeigniter url 路由应该可以帮助您。参考:https ://codeigniter.com/user_guide/general/routing.html

冉冉说

在名为 (.htaccess) 的主文件夹中创建一个新文件,并将此代码粘贴到 .htaccess 文件中。<IfModule mod_rewrite.c>&nbsp;RewriteEngine On&nbsp;RewriteBase /Enter your folder name/删除用户对系统文件夹的访问。此外,这将允许您创建一个 System.php 控制器,以前这是不可能的。如果您已重命名系统文件夹,则可以替换系统。RewriteCond %{REQUEST_URI} ^system.*RewriteRule ^(.*)$ /index.php?/$1 [L]当您的应用程序文件夹不在系统文件夹中时此代码段可防止用户访问应用程序文件夹将“应用程序”重命名为您的应用程序文件夹名称。&nbsp;RewriteCond %{REQUEST_URI} ^application.*&nbsp;RewriteRule ^(.*)$ /index.php?/$1 [L]检查到&nbsp;Rewrite Cond %{ENV:REDIRECT_STATUS} ^$&nbsp; &nbsp;&nbsp;&nbsp;Rewrite Cond %{REQUEST_FILENAME} !-f&nbsp; &nbsp;&nbsp;&nbsp;Rewrite Cond %{REQUEST_FILENAME} !-d&nbsp; &nbsp;&nbsp;&nbsp;RewriteRule ^(.*)$ index.php?/$1 [L]&nbsp; &nbsp;&nbsp;</IfModule>错误文档 404 /index.php

30秒到达战场

.htaccess您可以在根文件夹的文件中尝试以下代码吗<IfModule mod_rewrite.c>RewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^(.*)$ index.php/$1 [L]</IfModule>

ABOUTYOU

尝试这个RewriteRule ^(.*)$ index.php?/$1 [L,QSA]&nbsp;QSA表示如果有一个查询字符串与原始 URL 一起传递,它将被附加到重写然后这样做//remove index.php$config['index_page'] = '';$config['uri_protocol'] = 'REQUEST_URI';
打开App,查看更多内容
随时随地看视频慕课网APP