2015-11-23 133 views
0

我有一个房地产网站,在笨我的链接名称是:笨更改URL路由

htp://examplesite(dot)com/property/31/en/property_title

我想取代它:

htp://examplesite(dot)com/my-custom-slug.htm

htp://examplesite(dot)com/property_title

两种方式都可以。我的路线是:

$route['default_controller'] = "frontend"; 
$route['404_override'] = 'frontend'; 

/* Custom routing */ 
$route['admin'] = 'admin/dashboard'; 
//$route['secret'] = 'admin/dashboard'; 

// To change property->listing in uri 
$route['listing/(:num)/(:any)/(:any)'] = "property/$1/$2/$3"; 
$route['listing/(:num)/(:any)'] = "property/$1/$2"; 

这种情况下最好的方法是什么?

我知道有一个可能的解决方案是:

添加

$配置[ 'listing_uri'] = '上市';

不是增加:

在 '应用程序\设置\ routes.php文件'

后:

$route['listing/(:num)/(:any)/(:any)'] = "property/$1/$2/$3"; 
$route['listing/(:num)/(:any)'] = "property/$1/$2"; 

添加也:

$route['changed/(:num)/(:any)/(:any)'] = "property/$1/$2/$3"; 
$route['changed/(:num)/(:any)'] = "property/$1/$2"; 

,但有什么办法删除'上市',只看到干净的网址(为了更好的SEO目的)??

回答

2

欢迎,幸运的是,你的问题不是太大:)

也许有产权前一个金属块,使该解决方案有点更具可扩展性:

$route["listing/(:any)"] = "property/view/$1"; 

浏览器然后指向yoursite.com/listing/some_slugyoursite.com/listing/12

您将需要有一个slug与每个属性关联,否则您可以使用id,并在视图函数中检索基于slug或id参数的属性。

如果您不想包含listing/,尝试创建其他路线时可能会遇到问题。

+0

我只是写了同样的东西,但后来你发布在我面前:-) – cartalot

+0

我知道有一个解决方案来添加:$ config ['listing_uri'] ='listing';比添加$ route ['changed /(:num)/(:any)/(:any)'] =“property/$ 1/$ 2/$ 3”; $ route ['changed /(:num)/(:any)'] =“property/$ 1/$ 2”;但我想删除列表,并只看到examplesite(dot)com/custom_slug.htm有没有什么办法? – Fuente

+0

我不确定我是否理解你的意思,你能否详细说明一下?您可以使用上面提到的解决方案而不使用列表部分,如果您有任何其他特定路由,只需在配置文件的此路由之前添加它即可,因为codeigniter会自上而下地解释它。这个问题是你假设你的域名是一个有效的上市后,所以你的验证只需要声音,并显示404,如果上市不存在 – peanut