[英]How to Remove index.php in URL
我尝试删除 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
您好是控制器,最后感谢您的帮助,:)
问题是,你把它安装在/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> 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
试试这个
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
QSA
意味着如果有一个查询字符串与原始 URL 一起传递,它将被附加到重写
然后这样做
//remove index.php
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';
您可以在根文件夹的.htaccess
文件中尝试以下代码吗
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
请遵循以下流程:
.htaccess
文件检查服务器上是否启用了mod_rewrite ?
RewriteEngine On RewriteCond %{REQUEST_FILENAME}.-f RewriteCond %{REQUEST_FILENAME}.-d RewriteRule ^(.*)$ index.php/$1 [L]`
这将解决您的问题。 如果您仍然面临问题,请告诉我。
试试这个步骤:
$config['index_page'] = "index.php"
中删除 index.php 在项目根文件夹中创建.htaccess
,如下代码
RewriteEngine on RewriteBase /codeigniter3/ RewriteCond $1.^(index\.php|css|fonts|images|js) RewriteRule ^(.*)$ index?php?/$1 [L]
然后尝试http://localhost:8089/codeigniter3/Hello/dispdata
我希望它能解决你的问题!
RewriteRule ^(.*)$ index.php/$1 [L]
由于您在.htaccess
指令中将正确的 URL 路径作为附加路径名信息(path_info) 传递,因此请尝试在配置中显式设置它:
$config['uri_protocol'] = 'path_info';
除非明确设置,否则它将尝试各种方法,这些方法可能会失败,因为您现在已经从 URL 中删除了index.php
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.