我正在使用 codeigniter...我想要一个来自以下 URL 的干净 URL
localhost:8080/rtvnews/index.php/home/videonews?id=67598/newstitle这里 home => 控制器,videonews => 函数,?id=6586565 是一个 url 字符串.
我想删除/index.php/home/videonews?id=67598 并替换为/news/
在我需要获取的最终网址下方
localhost:8080/rtvnews/news/newstitle 解决方案为了在 url 中隐藏 index.php 使用以下 htaccess
RewriteEngine OnRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-d重写规则 ^(.*)$ index.php/$1 [L]更多关于 htaccess
URI 路由
将新闻标题视为唯一:
转到您的 route.php 文件 (application/config/routes.php).添新路由规则如下
$route['rtvnews/news/(:any)'] = 'home/videonews/$1';在您的视图文件中
<a href="<?php echo base_url()."rtvnews/new/".$newstitle; ?>">新闻标题</a>所以你的网址变成如下
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>所以你的网址变成如下
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
localhost:8080/rtvnews/index.php/home/videonews?id=67598/newstitlehere 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
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]More on htaccess
URI Routing
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
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
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隐藏网址
发布评论