php - ci url 是否可能不适用于 index.php

标签 php codeigniter .htaccess

是否有可能 ci url 不能与 index.php 一起使用。我不想在 url 中添加 index.php。如果有人在 url 中添加 index.php 它应该不起作用。我已经尝试了很多方法。请给我建议。 我已经尝试过了,但它不起作用

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

例如

如果我使用下面的 url 这应该可以工作......................

`example.com/abc`

如果我使用下面的 url 不应该工作

`example.com/index.php/abc`

最佳答案

在您的根目录中创建 .htaccess 文件并将此代码保存在其中

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

打开application/config/config.php

    //find the below code   
$config['index_page'] = "index.php" 
//replace with the below code
$config['index_page'] = ""

/find the below code
$config['uri_protocol'] = "AUTO"
//replace with the below code
$config['uri_protocol'] = "REQUEST_URI" 

关于php - ci url 是否可能不适用于 index.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51665022/

相关文章:

javascript - 无法读取房地产谷歌图表

regex - HT访问: Replace URL with the help of regex

.htaccess从子文件夹重定向到域名

php - 通过 htaccess 为登录用户强制 https

php - 有没有办法让 FPDF/FPDI 或 Zend_Pdf 支持解析大于 1.4 的 PDF?

php - 使用 .htaccess 强制某些页面在 SSL 站点上使用非 SSL

CodeIgniter 表类 : Add a Link From a Generated Cell

javascript - 如何使用 codeigniter(由 javascript 代码捕获的图像)将捕获的图像保存在文件夹中?

javascript - 电子邮件发送表单、复选框选择、复选框限制

javascript - Canvas 的 ToDataURL (JavaScript) 在通过 PHP 上传到服务器后创建损坏的 PNG 文件