[英]Rewrite url of different pages to the same url in codeigniter
I want to rewrite url in codeigniter 我想在codeigniter中重写url
For Products pages I want to change from given url 对于产品页面,我想从给定的URL更改
www.example.com/services/service-name
TO 至
www.example.com/service-name
For Services pages I want to change from given url 对于我想要从给定URL更改的服务页面
www.example.com/products/product-name
TO 至
www.example.com/product-name
But links are not working. 但链接不起作用。 It is not differentiating between products and services url.
它不区分产品和服务网址。 It get confused that whether the url is related to products or services.
令人感到困惑的是,网址是否与产品或服务有关。 which particular page should be fetched.?
应该提取哪个特定页面。
First, wildcard route must be at the end 首先,通配符路由必须在最后
$route['some-route'] = 'ctrl/m/$1';
$route['some-other-route'] = 'ctrl/m2/$1';
...
$route['(:any)'] = 'ctrl/m3/$1';
Routes will run in the order they are defined.
路由将按照定义的顺序运行。 Higher routes will always take precedence over lower ones.
较高的路线始终优先于较低的路线。
Second, having difference in route is good way to go because 其次,在路线上有差异是很好的方法,因为
/services/
or /products/
you need to pay attention on insert not to duplicate name between different areas (ie services, products). /services/
或/products/
等细分,则需要注意插入不要在不同区域(即服务,产品)之间复制名称。 Routing works in a way value is taken from URL and application is going to do something with that value. 路由工作的方式是从URL获取值,应用程序将使用该值执行某些操作。 If you have route
如果你有路线
https://www.example.com/making-powerplant
application doesn't know if making-powerplant is service or product. 应用程序不知道制造动力装置是服务还是产品。 So if you made everything on insert data or on insert
making-powerplant
to avoid doubling that title from services and products, now your application should query both tables. 因此,如果您在插入数据或插入
making-powerplant
上making-powerplant
了所有内容以避免将该标题从服务和产品中加倍,那么现在您的应用程序应该查询两个表。 First it should query services table to see if there is title like that one. 首先,它应该查询服务表,看看是否有像那样的标题。 If title is not found in services table, application would need to query products table.
如果在services表中找不到title,则应用程序需要查询products表。 That would be verbose app and code design since in most cases you are making query that you don't need.
这将是冗长的应用程序和代码设计,因为在大多数情况下,您正在进行不需要的查询。 But that is only way you check two tables or two sources from one URI segment.
但这只是你从一个URI段检查两个表或两个源的方法。 I would stick with
/services/service-1
and /products/product-1
. 我会坚持使用
/services/service-1
和/products/product-1
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.