使用Codeigniter进行网址隐藏 [英] Url hide using codeigniter

查看:71
本文介绍了使用Codeigniter进行网址隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用codeigniter ...我想从URL下方获取干净的URL

I am using codeigniter... I want a clean URL from below URL

  http://localhost:8080/rtvnews/index.php/home/videonews?id=67598/newstitle 

此处home =>控制器, videonews =>函数,?id = 6586565是一个URL字符串。

here home => controller, videonews => function and ?id=6586565 is a url string.

我要删除/index.php/home/videonews?id=67598并替换为/ news /

I want to remove /index.php/home/videonews?id=67598 and replace with /news/

在最终网址下方,我需要获取

Below Final url I need to get

  http://localhost:8080/rtvnews/news/newstitle 


推荐答案

要在网址中隐藏index.php,请使用以下htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

有关htaccess的更多信息

URI路由

考虑新闻标题如唯一:


转到您的route.php文件(application / config / routes.php)。如下添加新的
路由规则

Go to your route.php file (application/config/routes.php) . Add new route rule as below



$route['rtvnews/news/(:any)'] = 'home/videonews/$1';




在您的视图文件中

in your view file



<a href="<?php echo base_url()."rtvnews/new/".$newstitle; ?>" > News Title</a>




因此您的网址如下

so your url became as below



http://localhost:8080/rtvnews/news/uniquenewstitle  




您的请求转到home / vidonews函数,您可以在其中获取
新闻标题作为参数。

Your request go to home/vidonews function where you can get your newstitle as parameter.

在controller.php函数中将类似于

In your controller.php function will be like



function vidonews($newsTitle){}

将id视为唯一的:


如下添加新的路线规则

Add new route rule as below



$route['rtvnews/news/(:num)'] = 'home/videonews/$1';




在view.php文件中

In view.php file



<a href="<?php echo base_url()."rtvnews/new/".$newsId; ?>" > News Title</a>




因此您的网址如下

so your url became as below



http://localhost:8080/rtvnews/news/newsId




现在,您的请求转到home / vidonews函数,您可以在其中获取
newsId作为参数。在您的controller.php函数中将类似于

Now your request go to home/vidonews function where you can get your newsId as parameter. In your controller.php function will be like



function vidonews($newsId){}

这篇关于使用Codeigniter进行网址隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆