Welcome Guest, Not a member yet? Register   Sign In
routes and spaces (% 20)
#1

[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)
#2

[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
$title = 'page title';

// url
$url = 'http:/domain.tld/page-title';

// sql
WHERE title LIKE 'page_title'

The underscore is a wildcard here.
#3

[eluser]Phil Sturgeon[/eluser]
Wrap your slugs in url_title().
#4

[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
#5

[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




Theme © iAndrew 2016 - Forum software by © MyBB