简体   繁体   English

重写或重定向到Codeigniter中的当前页面

[英]rewrite or redirect to curent page in codeigniter

hello guys i want to ask if there possible to rewrite or redirect to current page url if we are change our link page by manual in link bar? 大家好,我想问一下如果我们要通过链接栏中的手册来更改链接页面,是否可以重写或重定向到当前页面的URL?

example : 例如:

our current link is www.example.com/example/data-data/link-link 我们当前的链接是www.example.com/example/data-data/link-link

than im change that current link in the link bar become : 比即时更改链接栏中的当前链接变为:

www.example.com/example/data-data/link-li

than

if the link was changed will be 如果链接被更改将是

redirect to www.example.com/example/data-data/link-link 重定向到www.example.com/example/data-data/link-link

if it is possible please guide me how to do it 如果可能的话,请指导我怎么做

thank you 谢谢

Yes it is possible to do, all you have to do is follow the steps 是的,有可能做,您所要做的就是遵循以下步骤

  1. Change your routes.php file as following (Replace 404_override with Errors controller's index method) 如下更改您的routes.php文件(用Errors控制器的index方法替换404_override

     $route['404_override'] = 'errors/index'; 
  2. Now create a Errors controller with index method in your controllers directory with following code 现在,使用以下代码在您的controllers目录中创建一个带有index方法的Errors控制器。

     defined('BASEPATH') OR exit('No direct script access allowed'); class Errors extends CI_Controller { public function index() { redirect($this->router->fetch_class()); } } 

Now when you will browse any wrong link it will redirect you to corresponding controller from where you mistype. 现在,当您浏览任何错误的链接时,它将把您重定向到您输入错误的位置的相应控制器。

Yes It is possible in codeigniter you only need to make route for this link after that you can redirect where ever you want. 是的,在codeigniter中,您可能只需要为该链接进行路由,之后便可以将其重定向到所需的任何位置。

In codeigniter version 3 :- 在codeigniter版本3中:-

File is located in :- application\\config\\routes.php 文件位于:-application \\ config \\ routes.php

make your route and give which controller you want to run. 确定路线,并指定要运行的控制器。

$route['example/data-data/link-li'] = 'your controller name';

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

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