routes and spaces (% 20) |
[eluser]Anonymous[/eluser]
Hi, I am finetuning a website i have developed. It has a CMS in it, where the customer can create pages. Before, they would be reached through Code: http://domain/home/page/a page/ I want to remove the /home/page/ part for most of the pages, so i added a route to the routes.php file. Code: $route['^(?!admin|auth|backend|shop)\S*'] = "/home/page/$1/"; The problem however is that URL's with a space in it (% 20) won't work anymore. Is there a workaround for this? (besides adding a slug field in the db)
[eluser]n0xie[/eluser]
One option would be to replace spaces with a token (the hyphen is usually used). Then change the SQL to change hyphen's to wildcards to find the field with the space. Something like this: Code: // page title The underscore is a wildcard here.
[eluser]Christophe Sautot[/eluser]
You do have a valid question, and spaces should be allowed in your URI segments. There are 2 options I can think of. 1) You create a function in your controller to handle all incoming traffic for that URI segment, and then the function decides where to route the traffic. Code: $route['tags/(.*)'] = "tags/route_uri/$1"; In tags.php controller: route_uri($segment_value) 2) Not sure if this will work, but you use [:SPACE:] in your regular expression used in config/routes.php
[eluser]Anonymous[/eluser]
For those who care. The solution was in the route statement. I changed the route to: Code: $route['^(?!admin|auth|backend|shop)(:any)'] = "/home/page/$1/"; Now it allows spaces in the uri |
Welcome Guest, Not a member yet? Register Sign In |