是否有可能ci url不能与index.php一起使用

use*_*563 6 php .htaccess codeigniter 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]
Run Code Online (Sandbox Code Playgroud)

例如

如果我使用下面的网址这应该工作..............

`example.com/abc`
Run Code Online (Sandbox Code Playgroud)

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

`example.com/index.php/abc`
Run Code Online (Sandbox Code Playgroud)

Avi*_*Avi 6

尝试以下代码。

在config.php中更改以下内容

$config['index_page'] = ""
$config['uri_protocol'] = "REQUEST_URI"
Run Code Online (Sandbox Code Playgroud)

现在打开.htaccess文件,并替换为以下代码。

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Run Code Online (Sandbox Code Playgroud)

如果以上索引行不起作用,请用新代码替换该行。因为.htaccess取决于服务器

// Replace last .htaccess line with this line
   RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Run Code Online (Sandbox Code Playgroud)


小智 1

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

if(strpos($_SERVER['REQUEST_URI'],'index.php') !== false){
    header('location: http://xyx.com/404');
    die();
}
Run Code Online (Sandbox Code Playgroud)