簡體   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