Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

product detail page routing in codeigniter

In my local site

http://localhost/giftsware/nl/products/details/2382

This is my browser url for product description page now I want more user friendly url for product description page. I want to change above url to

http://localhost/giftsware/products/2382

I tried by routing all calls to details by adding

$route['products/(:any)'] = "nl/products/details/$1";

this is in routes.php file, but it gives me 404 error. What could be the possible issue and how can I fix it?

this is my complete route file code

$route['(:any)/products/(:num)'] = "products/details/$2";
$route['default_controller'] = "pages";
$route['404_override'] = '';

$route['^en/admin/([a-zA-Z_-]+)/(:any)']    = '$1/admin/$2';
$route['^en/admin/(login|logout)']          = 'admin/$1';
$route['^en/admin/([a-zA-Z_-]+)']           = '$1/admin/index';
$route['^nl/admin/([a-zA-Z_-]+)/(:any)']    = '$1/admin/$2';
$route['^nl/admin/(login|logout)']          = 'admin/$1';
$route['^nl/admin/([a-zA-Z_-]+)']           = '$1/admin/index';
$route['admin']                         = 'admin'; 

$route['pages/(:any)'] = "pages/index/$1";


$route['^nl/(.+)$'] = "$1";
$route['^en/(.+)$'] = "$1";


$route['^nl$'] = $route['default_controller'];
$route['^en$'] = $route['default_controller'];
like image 573
Mayur Kukadiya Avatar asked Nov 10 '22 16:11

Mayur Kukadiya


1 Answers

Try it

$route['^nl/products/details/(\d+)$'] = 'products/$1';

Using .htaccess files

  Options +FollowSymLinks
      RewriteEngine On

      RewriteCond %{SCRIPT_FILENAME} !-d
      RewriteCond %{SCRIPT_FILENAME} !-f

      RewriteRule ^products/(\d+)*$ ./nl/products/details/$1

Using php

<?php
    #remove the directory path we don't want
    $request  = str_replace("nl/products/details", "products", $_SERVER['REQUEST_URI']);
  ?>
like image 199
Sorbo Avatar answered Nov 15 '22 05:11

Sorbo