[英]Blocking direct access to index.php with CodeIgniter
I've managed to remove the need for typing index.php
in my urls, but it is still possible to do so.我已经设法消除了在我的网址中输入
index.php
的需要,但仍然可以这样做。 I don't want that and want to prevent users to be able to access my application via urls like /index.php/home
or /index.php/contact
or even /index.php
.我不希望这样,并希望阻止用户通过 /index.php/home 或
/index.php/contact
甚至/index.php/home
等网址访问我的应用/index.php
。
Does anyone know how to accomplish this?有谁知道如何做到这一点?
In you .htaccess
write in the top在你
.htaccess
写在最上面
DirectoryIndex my_new_index.php
RewriteEngine on
RewriteCond $1 !^(my_new_index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /my_new_index.php/$1 [L]
Rename your index.php
file to my_new_index.php
将
index.php
文件重命名为my_new_index.php
If you're using Apache, then just setup a rewrite rule to redirect users from index.php to /如果您使用的是 Apache,那么只需设置重写规则将用户从 index.php 重定向到 /
RewriteRule ^/index\.php$ /
RewriteRule ^/index\.php/(.*) /$1
Exactly.确切地。 Here's an example:
这是一个例子:
RewriteRule ^foo\.html$ bar.html
Or you can use variables like so:或者你可以像这样使用变量:
^hotsheet/(.*)$ http://www.tstimpreso.com/hotsheet/$1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.