简体   繁体   English

如何删除 URL 中的 index.php

[英]How to Remove index.php in URL

I try to remove the index page in Codeigniter我尝试删除 Codeigniter 中的索引页

the first step I do this //old Code我这样做的第一步//旧代码

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

//New updated code(Only Need to remove index.php ) //新更新的代码(只需要删除 index.php )

$config['index_page'] = ""

then for second step i do this creat file .htaccess in root of codigniter then put this code source然后第二步,我在 codigniter 的根目录中创建文件 .htaccess,然后将此代码源

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

but it's the same problem and I can't refresh the web page但这是同样的问题,我无法刷新网页

with index page the URL work: http://localhost:8089/codeigniter3/index.php/Hello/dispdata but without index page don't work http://localhost:8089/codeigniter3/Hello/dispdata有索引页的 URL 工作: http://localhost:8089/codeigniter3/index.php/Hello/dispdata但没有索引页不工作http://localhost:8089/codeigniter3/Hello/dispdata

Hello is the controller, finally thank for help, :)您好是控制器,最后感谢您的帮助,:)

The problem is, you installed it in /codeigniter3/问题是,你把它安装在/codeigniter3/

This should fix it:这应该修复它:

// remove index.php
$config['index_page'] = ""

// Allow installation in a subfolder of your webroot
$config['uri_protocol'] = "REQUEST_URI"

And keep your rewrite settings, they are ok.并保留您的重写设置,它们没问题。

Codeigniter url routing should come to your rescue. Codeigniter url 路由应该可以帮到你。 Refer: https://codeigniter.com/user_guide/general/routing.html参考: https ://codeigniter.com/user_guide/general/routing.html

  1. Create a new File In Main Folder Named as (.htaccess) and paste this code in .htaccess file.在名为 (.htaccess) 的主文件夹中创建一个新文件,并将此代码粘贴到 .htaccess 文件中。

     <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /Enter your folder name/
  2. Removes access to the system folder by users.删除用户对系统文件夹的访问权限。 Additionally this will allow you to create a System.php controller, previously this would not have been possible.此外,这将允许您创建一个 System.php 控制器,以前这是不可能的。 system can be replaced if you have renamed your system folder.如果您重命名了系统文件夹,则可以更换系统。

     RewriteCond %{REQUEST_URI} ^system.* RewriteRule ^(.*)$ /index.php?/$1 [L]

When your application folder isn't in the system folder This snippet prevents user access to the application folder当您的应用程序文件夹不在系统文件夹中时此代码段会阻止用户访问应用程序文件夹

  1. Rename 'application' to your applications folder name.将“应用程序”重命名为您的应用程序文件夹名称。

     RewriteCond %{REQUEST_URI} ^application.* RewriteRule ^(.*)$ /index.php?/$1 [L]

Checks to检查到

 Rewrite Cond %{ENV:REDIRECT_STATUS} ^$    
 Rewrite Cond %{REQUEST_FILENAME} !-f    
 Rewrite Cond %{REQUEST_FILENAME} !-d    
 RewriteRule ^(.*)$ index.php?/$1 [L]    
</IfModule>

ErrorDocument 404 /index.php错误文档 404 /index.php

try this试试这个

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

QSA means that if there's a query string passed with the original URL, it will be appended to the rewrite QSA意味着如果有一个查询字符串与原始 URL 一起传递,它将被附加到重写

And then do this然后这样做

//remove index.php
$config['index_page'] = '';

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

Can you try the below code in your .htaccess file on root folder您可以在根文件夹的.htaccess文件中尝试以下代码吗

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

Please follow the below process:请遵循以下流程:

  1. Create .htaccess file in the project root folder在项目根文件夹中创建.htaccess文件
  2. Check whether mod_rewrite is enable on server?检查服务器上是否启用了mod_rewrite

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

This will resolve your issue.这将解决您的问题。 Let me know if you are still facing issue.如果您仍然面临问题,请告诉我。

Try this step:试试这个步骤:

  1. remove index.php from $config['index_page'] = "index.php"$config['index_page'] = "index.php"中删除 index.php
  2. create .htaccess in the project root folder like below code在项目根文件夹中创建.htaccess ,如下代码

    RewriteEngine on RewriteBase /codeigniter3/ RewriteCond $1.^(index\.php|css|fonts|images|js) RewriteRule ^(.*)$ index?php?/$1 [L]

    Then try http://localhost:8089/codeigniter3/Hello/dispdata然后尝试http://localhost:8089/codeigniter3/Hello/dispdata

I hope it will fix your problem!我希望它能解决你的问题!

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

Since you are passing the correct URL-path as additional pathname information (path_info) in your .htaccess directive then try explicitly setting this in the config:由于您在.htaccess指令中将正确的 URL 路径作为附加路径名信息(path_info) 传递,因此请尝试在配置中显式设置它:

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

Unless this is set explicitly then it will try various methods, which may be failing since you have now removed index.php from the URL.除非明确设置,否则它将尝试各种方法,这些方法可能会失败,因为您现在已经从 URL 中删除了index.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM