简体   繁体   English

如何在codeigniter中使用破折号路由uri

[英]how to route uri with dash in codeigniter

I am trying to control my routing in codeigniter. 我试图控制我在codeigniter中的路由。

I have my url which is: www.domain.com/all-artists . 我的网址是: www.domain.com/all-artists If I am going to accept the dash controller, I need to configure the route.php below: 如果我要接受破折号控制器,则需要在下面配置route.php:

 <?php $route['all-artists']  =  "all_artists";

The above routing works. 以上路由有效。 Now, I want to visit this url: www.domain.com/all-artists/x 现在,我想访问此URL: www.domain.com/all-artists/x

The "x" method from the uri above is dynamic, which means that I can change it from az. 上面uri中的“ x”方法是动态的,这意味着我可以从az更改它。 However, this url returns an error display. 但是,此url返回错误显示。

Do you know how to route these urls that can accept even segment(1) with dashed and contains dynamic methods? 您是否知道如何路由这些甚至可以接受带有虚线的segment(1)并包含动态方法的URL?

I got this routing: 我得到了这个路由:

 <?php //route.php
 $route['all-artists']          =  "all_artists";
 $route['all-artists/(:any)']  =  "all_artists/function_name/$1";
 ?>

This routing will accept both www.domain.com/all-artists and www.domain.com/all-artists/x 此路由将接受www.domain.com/all-artistswww.domain.com/all-artists/x

RewriteRule ^([^_]*)_([^_]*_.*) $1-$2 [N]
RewriteRule ^([^_]*)_([^_]*)$ /$1-$2 [L,R=301]

Using a htaccess rule above something like that you can replace underscores with dashes. 使用类似这样的htaccess规则,您可以将下划线替换为破折号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM