首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >ci url是否可能无法与index.php一起使用?

ci url是否可能无法与index.php一起使用?
EN

Stack Overflow用户
提问于 2018-08-03 11:45:30
回答 7查看 204关注 0票数 6

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

代码语言:javascript
复制
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

例如,用于

如果我使用下面的url,这应该是有效的.............

代码语言:javascript
复制
`example.com/abc`

如果我使用下面的链接,url不会起作用

代码语言:javascript
复制
`example.com/index.php/abc`
EN

回答 7

Stack Overflow用户

回答已采纳

发布于 2018-08-18 14:48:04

在index.php的顶部添加以下代码。我想这会解决你的问题。

代码语言:javascript
复制
if(strpos($_SERVER['REQUEST_URI'],'index.php') !== false){
    header('location: http://xyx.com/404');
    die();
}
票数 1
EN

Stack Overflow用户

发布于 2018-08-03 13:23:04

在根目录中创建.htaccess文件,并将以下代码保存在该文件中

代码语言:javascript
复制
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule>

打开application/config/config.php

代码语言:javascript
复制
    //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" 
票数 3
EN

Stack Overflow用户

发布于 2018-08-19 00:39:18

您可以使用:

代码语言:javascript
复制
RewriteEngine On

# 403 Forbidden for index.php
RewriteCond %{THE_REQUEST} index\.php [NC]
RewriteRule ^ - [F]

# Rewrite to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51665022

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档