繁体   English   中英

使用 CodeIgniter 阻止对 index.php 的直接访问

[英]Blocking direct access to index.php with CodeIgniter

我已经设法消除了在我的网址中输入index.php的需要,但仍然可以这样做。 我不希望这样,并希望阻止用户通过 /index.php/home 或/index.php/contact甚至/index.php/home等网址访问我的应用/index.php

有谁知道如何做到这一点?

在你.htaccess写在最上面

DirectoryIndex my_new_index.php

RewriteEngine on
RewriteCond $1 !^(my_new_index\.php|images|robots\.txt) 
RewriteRule ^(.*)$ /my_new_index.php/$1 [L]

index.php文件重命名为my_new_index.php

如果您使用的是 Apache,那么只需设置重写规则将用户从 index.php 重定向到 /

RewriteRule ^/index\.php$ /
RewriteRule ^/index\.php/(.*) /$1

确切地。 这是一个例子:

RewriteRule    ^foo\.html$  bar.html

或者你可以像这样使用变量:

^hotsheet/(.*)$  http://www.tstimpreso.com/hotsheet/$1

暂无
暂无

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

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