too long

I have an application where URL after rewriting are like this

http://www.domain.com/product/seller/product_id

an example link would be

http://storeiown.com/product/kitchenking/92013

This was okay but I need the title of the product to be included in the url

http://storeiown.com/product/a-very-nice-electric-cooker-by-kitchenking/92013

I achieved this too and all was good.

Now, I want all the url which do not include the title to redirect to this one. Like, if user lands from the url without the title they should be redirected to a version of the page with the url containing the title in the url.

How do i accomplish that. And for info additional info I use CodeIgniter in the app, if that makes it any easier.

you can do this way which i use. In the previous page type this at the top:-

<?php
session_start();
$_SESSION['mainpass']= '0';
?>

And in the next page code this at the top of the page :-

<?php
session_start;
if(isset($_SESSION['mainpass'])) {
//run the current page
}else{
header("location: www.domain.com");
}
?>

If you are using codeigniter, you could try the below.

$seg3 = $this->uri->segment(3);
if(is_numeric($seg3)){
//The user has come without the header because the third segment is numeric thus probably using the product id. 
//Therefore, redirect again to the proper link after getting the heading from your db
} else {
// do nothing
// the seg3 is not numeric means it probably came through normal preferred way
}

And in order to use the

$this->uri->segment(3);

You need to either

  • auto load the url helper

  • load manually when required