In my project, I am passing parameters through URL like,
http://site.org/project/controllername/function?id=1&type=free
What I want is to change the URL to
http://site.org/project/controllername/function/1/free
Actually I am creating the URLs dynamically like
<a href="<?php echo base_url()?>controllername/function?id=<?php echo $defaultrow->id;?>&type=free">
Controller Code :
// Inside VideoController
function search()
{
$userid=$this->tank_auth->get_user_id();
$data['userid']=$userid;
$time=time();
$data['defaultvideoquery']=$this->db->query("select cv.videotitle,cv.video,cv.thumbnail,
cv.added_on,cp.description,cv.id,cv.likes,cv.dislikes,cv.views from channel_programmes as cp INNER JOIN channel_videos as cv
ON cp.programme_source=cv.id and cp.channel_id=0 and $time>=cp.starttime and $time>=cp.endtime and cp.status=1");
$data['videonum']=$data['defaultvideoquery']->num_rows();
$data['page']='video/search';
$this->load->view('layout/template',$data);
}
// Inside ChannelsController
function playchannel()
{
if (!$this->tank_auth->is_logged_in())
{ // not logged in
redirect('auth/login');
}
$data['id']=$userid;
$id=$this->input->get('id');
if($this->input->get('type'))
{
if($this->input->get('type')=="free")
{
$time=time();
$data['currentdate']=$time;
$pgmquery=$this->db->query("select cp.channel_id,cp.title,cp.programme_source,cp.url,cp.description,cv.status,cv.video,cp.starttime,cp.endtime from
channel_videos as cv INNER JOIN channel_programmes as cp ON cv.id=cp.programme_source where cp.status=1 and cv.id=$id");
}
else
{
$query=$this->db->query("select id,title,thumbnail,channel_type,created_on,status,channel_type,description from videochannel
where created_for=$userid and id=$id");
$data['queryresult']=$query->row();
$data['channeldata']=$query->result();
}
$data['pgmnum']=$pgmquery->num_rows();
$data['pgmresult']=$pgmquery->result();
}
$data['page']='channels/playchannel';
$this->load->view('layout/template',$data);
}
View Code:
if(isset($videonum))
{
if($videonum>0)
{
foreach($defaultvideoquery->result() as $defaultrow)
{?>
<a href="<?php echo base_url()?>channels/playchannel?id=<?php echo $defaultrow->id;?>&type=free">
<?php if($defaultrow->thumbnail=="")
{ ?>
<img src="<?php echo base_url();?>images/No_image.png" class="videothumb" alt="Video thumbnail <?php echo $defaultrow->videotitle;?>">
<?php }
else
{ ?>
<img src="<?php echo base_url();?>channel/<?php echo $defaultrow->id;?>/<?php echo $defaultrow->thumbnail;?>" class="videothumb" alt="Video thumbnail <?php echo $defaultrow->videotitle;?>">
<?php } ?>
</a>
}
}
}
Htaccess Code :
RewriteEngine On
RewriteBase /projectname/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule \.htaccess - [F]
RewriteRule (.*)(css\/)(.*)$ $2$3 [QSA,L]
RewriteRule (.*)(css\/smoothness\/images\/)(.*)$ $2$3 [QSA,L]
RewriteRule (.*)(js\/)(.*)$ $2$3 [QSA,L]
RewriteRule (.*)(js\/user\/)(.*)$ $2$3 [QSA,L]
RewriteRule (.*)(js\/user\/timeslots\/)(.*)$ $2$3 [QSA,L]
RewriteRule (.*)(channel_data\/)(.*)$ $2$3 [QSA,L]
RewriteRule (.*)(images\/)(.*)$ $2$3 [QSA,L]
RewriteRule (.*)(sliders\/)(.*)$ $2$3 [QSA,L]
RewriteRule (.*)(secure\/)(.*)$ $2$3 [QSA,L]
RewriteRule (.*)(userdata\/)(.*)$ $2$3 [QSA,L]
RewriteRule (.*)(channel\/)(.*)$ $2$3 [QSA,L]
RewriteRule (.*)(css\/admin\/)(.*)$ $2$3 [QSA,L]
RewriteRule (.*)(css\/screen\/)(.*)$ $2$3 [QSA,L]
RewriteRule (.*)(css\/skins\/)(.*)$ $2$3 [QSA,L]
RewriteRule (.*)(css\/fonts\/)(.*)$ $2$3 [QSA,L]
RewriteRule (.*)(css\/images\/)(.*)$ $2$3 [QSA,L]
RewriteRule (.*)(css\/smoothness\/)(.*)$ $2$3 [QSA,L]
RewriteRule (.*)(fonts\/)(.*)$ $2$3 [QSA,L]
RewriteCond %{request_uri} !^index\.php
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
Is there any method to do this in Codeigniter without using htaccess. I tried adding
//$route['(:any)'] = 'controllername/function/$1';
$routes['channels/playchannel/(:any)'] = 'channels/playchannel/$1';
in application/config/routes.php file. But it returned 404 (Page Not Found) Error
.
Can anyone help me to achieve this. Thanks in advance.