简体   繁体   中英

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. 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 .

Does anyone know how to accomplish this?

In you .htaccess write in the top

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

If you're using Apache, then just setup a rewrite rule to redirect users from index.php to /

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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