0
votes

I am trying to control my routing in codeigniter.

I have my url which is: www.domain.com/all-artists. If I am going to accept the dash controller, I need to configure the route.php below:

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

The above routing works. Now, I want to visit this url: www.domain.com/all-artists/x

The "x" method from the uri above is dynamic, which means that I can change it from a-z. However, this url returns an error display.

Do you know how to route these urls that can accept even segment(1) with dashed and contains dynamic methods?

2
read the routing docs wildcard section - charlietfl
I've used routing for how many years but this seems new to me... Why downvote? - smz
because the answer is in the CI manual...under routing...really not hard to find or look up - charlietfl
If the answer is in the manual, I ask you this question.Do you know the answer if it's in the manual? - smz
that's really irrelevant what I know...asking here should not be you first line of research effort...did you even look? Most people would start there when a method isn't working as expected. And the docs are easy to navigate - charlietfl

2 Answers

1
votes

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

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

Using a htaccess rule above something like that you can replace underscores with dashes.