使用codeigniter隐藏网址 [英] Url hide using codeigniter
问题描述
我正在使用 codeigniter...我想要一个来自以下 URL 的干净 URL
http://localhost:8080/rtvnews/index.php/home/videonews?id=67598/newstitle
这里 home => 控制器,videonews => 函数,?id=6586565 是一个 url 字符串.
我想删除/index.php/home/videonews?id=67598 并替换为/news/
在我需要获取的最终网址下方
http://localhost:8080/rtvnews/news/newstitle
为了在 url 中隐藏 index.php 使用以下 htaccess
RewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-d重写规则 ^(.*)$ index.php/$1 [L]
将新闻标题视为唯一:
<块引用>转到您的 route.php 文件 (application/config/routes.php).添新路由规则如下
$route['rtvnews/news/(:any)'] = 'home/videonews/$1';
<块引用>
在您的视图文件中
<a href="<?php echo base_url()."rtvnews/new/".$newstitle; ?>">新闻标题</a>
<块引用>
所以你的网址变成如下
http://localhost:8080/rtvnews/news/uniquenewstitle
<块引用>
您的请求转到 home/vidonews 功能,在那里您可以获得您的新闻标题作为参数.
在你的 controller.php 函数中会像
function vidonews($newsTitle){}
将 id 视为唯一的:
<块引用>如下添加新的路由规则
$route['rtvnews/news/(:num)'] = 'home/videonews/$1';
<块引用>
在view.php文件中
<a href="<?php echo base_url()."rtvnews/new/".$newsId; ?>">新闻标题</a>
<块引用>
所以你的网址变成如下
http://localhost:8080/rtvnews/news/newsId
<块引用>
现在您的请求转到 home/vidonews 功能,在那里您可以获取您的newsId 作为参数.在您的 controller.php 函数中将像
function vidonews($newsId){}
I am using codeigniter... I want a clean URL from below URL
http://localhost:8080/rtvnews/index.php/home/videonews?id=67598/newstitle
here home => controller, videonews => function and ?id=6586565 is a url string.
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
For hiding index.php from url use following htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Considering newstitle as unique:
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
Your request go to home/vidonews function where you can get your newstitle as parameter.
In your controller.php function will be like
function vidonews($newsTitle){}
Considering id as unique :
Add new route rule as below
$route['rtvnews/news/(:num)'] = 'home/videonews/$1';
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
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屋!