codeigniter中的产品详细信息页面路由

时间:2013-12-14 09:43:00

标签: php .htaccess mod-rewrite codeigniter-url codeigniter-routing

在我的本地网站

  

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

这是我的产品说明页面的浏览器网址 现在我想要更多用户友好的URL用于产品描述页面。我想将上面的网址更改为

  

http://localhost/giftsware/products/2382

我尝试通过添加

将所有调用路由到详细信息
  

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

这是在routes.php文件中,但它给了我404错误。 可能存在什么问题以及如何解决?

这是我的完整路线文件代码

$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'];

1 个答案:

答案 0 :(得分:1)

试试吧

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

使用.htaccess文件

  Options +FollowSymLinks
      RewriteEngine On

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

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

使用php

<?php
    #remove the directory path we don't want
    $request  = str_replace("nl/products/details", "products", $_SERVER['REQUEST_URI']);
  ?>