简体   繁体   English

Codeigniter htaccess重定向到控制器

[英]Codeigniter htaccess redirect to controller

Hellow i'm trying to redirect the user to a specific controller if someone uses get_file_contents on my website. 您好,如果有人在我的网站上使用get_file_contents,我正在尝试将用户重定向到特定的控制器。

Here is my code 这是我的代码

----------
# Options
Options -Multiviews
Options +FollowSymLinks

#Enable mod rewrite
RewriteEngine On

RewriteBase /codeigniter/

RewriteCond %{HTTP_USER_AGENT} ^$ [OR]
RewriteCond %{HTTP_USER_AGENT} ^(java|curl|wget).* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*(winhttp|HTTrack|clshttp|archiver|loader|email|harvest|extract|grab|miner|curl|wget|python|nikto|scan).* [NC,OR]
RewriteCond %{REQUEST_METHOD} !^(GET|POST|HEAD) [NC]

RewriteRule ^(.*)$ index.php?/$1 [L]
# Here im trying to go to index.php/hacks controller
# it always goes to default controller set in config
# i want to go to a specific controller
# how can i do this ?

For most of the cases, you can control redirects in application/config/routes.php 对于大多数情况,您可以在application/config/routes.php控制重定向

For example, if you want to redirect a user who requests http://mysite.com/page to http://mysite.com/page2 you will add in there: 例如,如果您要将请求http://mysite.com/page的用户重定向到http://mysite.com/page2您将在其中添加:

$route['page'] = "page2";

To change the controller you want to be called when the site is loaded with no data, you will have to change the default controller: 若要更改在站点加载无数据时要调用的控制器,您将必须更改默认控制器:

$route['default_controller'] = "hacks"

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

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