5

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'];
Mayur Kukadiya
  • 994
  • 6
  • 20
  • 2
    Are you sure you don't have a conflicting route somewhere? Your routing looks correct, I don't see any reason for it not to work. – mcryan Dec 16 '13 at 12:56
  • 1
    can you show your full routes.php file? the order in which the routes are declared is important, and often I had to change it so they don't conflict – Ben Dubuisson Dec 17 '13 at 03:03
  • Did you have a Class named nl? Did you have a method named products? – Erich García Oct 09 '17 at 17:40

1 Answers1

1

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']);
  ?>
Sorbo
  • 339
  • 1
  • 5