Welcome Guest, Not a member yet? Register   Sign In
urls with dashes, instead of underscores
#1

[eluser]LAMP Coder[/eluser]
I need my urls to use dashes instead of underscores.

main reason is that I already have a website and I don't want to change the url structures, that will be a lot of redirects for google.. if i do so.. and I don't want to deal with it.


What i want is.
1) If url "my-test-controller" is called, it should trigger "my_test_controller" controller.. if it exists.
2) If url "my-test-controller/with-a-method" is called, it should trigger "with_a_method" method under "my_test_controller" controller.

How can I do this?
#2

[eluser]LAMP Coder[/eluser]
so far, I have used $routes to re-write controller requests
and _remap to route method calls.

now, the problem here is that with _remap every method call gets transferred to the _remap function and I don't want to deal with the 404 pages in this controller.
#3

[eluser]LAMP Coder[/eluser]
Another idea is to use _call() method, but should i really go to that extent? Isn't there an in-built function in CI to do this? *scratching head*
#4

[eluser]LAMP Coder[/eluser]
or may be I can use a regex in $routes to replace all dashes with underscores?
#5

[eluser]LAMP Coder[/eluser]
anyone?
#6

[eluser]LAMP Coder[/eluser]
i have so far came up with following regex, i'm only using one dash per url as of now.. everything works except the second rule..

i.e. my-controler/simplemethod doesn't work


Code:
$route['([a-z]+)-([a-z]+)/([a-z]+)-([a-z]+)'] = "$1_$2/$3_$4";
$route['([a-z]+)-([a-z]+)/([a-z]+)'] = "$i_$2/$3";
$route['([a-z]+)-([a-z]+)'] = "$1_$2";
#7

[eluser]LAMP Coder[/eluser]
.....
#8

[eluser]umefarooq[/eluser]
Hi i checked you have to modify your route file i have create one function in my welcome controller you can see the route file modification and its working fine with me.

Code:
$route['blog/my-fun'] = "welcome/my_fun";
  url will be called  = controller and function will be called.
#9

[eluser]LAMP Coder[/eluser]
thanks umefarooq, but i need this to be done dynamically.. i dont want to edit/modify the configuration file every time I update website.

I have already figured it out, final solution was handling the method rewriting through _remap() function and controllers through a regex in configuration file.
#10

[eluser]darkhouse[/eluser]
What about doing this in the config file?

Code:
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';




Theme © iAndrew 2016 - Forum software by © MyBB