为了账号安全,请及时绑定邮箱和手机立即绑定

如何删除 URL 中的 index.php

如何删除 URL 中的 index.php

PHP
一只萌萌小番薯 2022-07-29 09:44:19
我尝试删除 Codeigniter 中的索引页第一步我这样做 //旧代码$config['index_page'] = "index.php”//新更新的代码(只需要删除 index.php )$config['index_page'] = ""然后对于第二步,我在 codigniter 的根目录中执行此创建文件 .htaccess 然后放入此代码源RewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^(.*)$ index.php/$1 [L]但这是同样的问题,我无法刷新网页带有索引页面的 URL 工作:http://localhost:8089/codeigniter3/index.php/Hello/dispdata 但没有索引页面不起作用http://localhost:8089/codeigniter3/Hello/dispdata您好是控制器,最后感谢您的帮助,:)
查看完整描述

5 回答

?
慕的地10843

TA贡献1785条经验 获得超8个赞

问题是,你把它安装在/codeigniter3/


这应该解决它:


// remove index.php

$config['index_page'] = ""


// Allow installation in a subfolder of your webroot

$config['uri_protocol'] = "REQUEST_URI"

并保留您的重写设置,它们没问题。


查看完整回答
反对 回复 2022-07-29
?
侃侃无极

TA贡献2051条经验 获得超10个赞

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


查看完整回答
反对 回复 2022-07-29
?
冉冉说

TA贡献1877条经验 获得超1个赞

在名为 (.htaccess) 的主文件夹中创建一个新文件,并将此代码粘贴到 .htaccess 文件中。


<IfModule mod_rewrite.c>

 RewriteEngine On

 RewriteBase /Enter your folder name/

删除用户对系统文件夹的访问。此外,这将允许您创建一个 System.php 控制器,以前这是不可能的。如果您已重命名系统文件夹,则可以替换系统。


RewriteCond %{REQUEST_URI} ^system.*

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

当您的应用程序文件夹不在系统文件夹中时此代码段可防止用户访问应用程序文件夹


将“应用程序”重命名为您的应用程序文件夹名称。


 RewriteCond %{REQUEST_URI} ^application.*

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

检查到


 Rewrite Cond %{ENV:REDIRECT_STATUS} ^$    

 Rewrite Cond %{REQUEST_FILENAME} !-f    

 Rewrite Cond %{REQUEST_FILENAME} !-d    

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

</IfModule>

错误文档 404 /index.php


查看完整回答
反对 回复 2022-07-29
?
30秒到达战场

TA贡献1828条经验 获得超6个赞

.htaccess您可以在根文件夹的文件中尝试以下代码吗


<IfModule mod_rewrite.c>

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

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

</IfModule>


查看完整回答
反对 回复 2022-07-29
?
ABOUTYOU

TA贡献1812条经验 获得超5个赞

尝试这个


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

QSA表示如果有一个查询字符串与原始 URL 一起传递,它将被附加到重写


然后这样做


//remove index.php

$config['index_page'] = '';


$config['uri_protocol'] = 'REQUEST_URI';


查看完整回答
反对 回复 2022-07-29
  • 5 回答
  • 0 关注
  • 218 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号