Forum

Thread tagged as: Problem, Runway

Using parentheses in a URL that's processed by Runway routing

Just using Runway routing for the first time. Really useful for what I'm doing, converting an existing site to Runway and making huge improvements to it.

But I've found an issue if a 'urlencoded' string contains the ( or ) - parentheses characters - and is used as a route. I can't show the site as its in development and protected for now, but here's the examples ...

This piece of text is a link ... Builders (Services & Contractors)

Its link is https://dev.xxxxxxx.co.uk/businesses/builders+%28services+%26+contractors%29/5 - and that link is created using urlencode.

The URL pattern in the route for the target page is ... businesses/[:title]/[:category]

Around 20+ other links on the page and another page all work fine and the target page is correctly displayed by Runway. All except this one, that's has parentheses - and its the only one with them. What that link does is display the website's index page.

If I use rawurlencode instead, the link becomes https://dev.xxxxxxx.co.uk/businesses/builders%20%28services%20%26%20contractors%29/5

That URL is not the one I'd prefer to have and use but when its clicked the routing works correctly and the target page is displayed in Runway.

It would appear that the Runway routing doesn't like parentheses created by urlencode. Maybe its a combination of the +( in the URL? Does that make any sense?

Thanks, Graham

Graham Street

Graham Street 17 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Have you created a token to match the pattern?

Reading through the documentation again, would not the default (built in) values work? This is my URL pattern (it wasn't displayed properly in the original post above) and presumably allows anything in the title and anything in the category?

businesses/[*:title]/[*:category]
Drew McLellan

Drew McLellan 2638 points
Perch Support

Yes, that should work.

That's what I though, but it doesn't. As described above. I could try Perch Debug on the page but I think it routes to 'index' before any debug info has a chance to appear. Want me to try anything else (apart from removing the parentheses)?

Drew McLellan

Drew McLellan 2638 points
Perch Support

I could try Perch Debug on the page but I think it routes to 'index' before any debug info has a chance to appear.

What do you mean?

I've now enabled debug on the page (that's a list of links) and the target page. For a link of https://dev.xxxxx.co.uk/businesses/architectural+services/65 - where the text for the link is Architectural Services - the correct target page is being displayed. The relevant part of the debug info shows this ...

Matched route: businesses/[*:title]/[*:category]
Using master page: /templates/pages/businesses_detail.php
Page arguments:
Array
(
    [0] => /businesses/architectural+services/65
    [title] => architectural+services
    [1] => architectural+services
    [category] => 65
    [2] => 65
)
[1] SELECT * FROM perch2_pages WHERE pagePath='/businesses/business-category' LIMIT 1

But, for a link of https://dev.xxxxx.co.uk/businesses/builders+%28services+%26+contractors%29/5 - where the text for the link is Builders (Services & Contractors) - no target page is loaded. The visitor is taken directly to the site's home page (/index), so there's no debug info to give you.

If I change that text from ... Builders (Services & Contractors) ... to Builders -Services & Contractors- as an example, the routing works and the correct target page is being displayed. The relevant part of the debug info shows this ...

Matched route: businesses/[*:title]/[*:category]
Using master page: /templates/pages/businesses_detail.php
Page arguments:
Array
(
    [0] => /businesses/builders+-services+&+contractors-/5
    [title] => builders+-services+&+contractors-
    [1] => builders+-services+&+contractors-
    [category] => 5
    [2] => 5
)
[1] SELECT * FROM perch2_pages WHERE pagePath='/businesses/business-category' LIMIT 1

So, basically it appears to me that something about the brackets/parentheses messes with something in the Runway routing code?

Extra info ... If I change the text to Builders (Services/Contractors) from Builders (Services & Contractors), the generated link changes to https://dev.xxxxx.co.uk/businesses/builders+%28services%2Fcontractors%29/5 and this works correctly. I also tried changing another category from Care & Nursing to (Care & Nursing) and the problem is then replicated there too.

So, maybe its the & within the parentheses that's causing the issue?

Graham

Drew McLellan

Drew McLellan 2638 points
Perch Support

What rewrite rules are you using to direct responses to the Runway start.php FC? Do those account for your URLs?

Just these in .htaccess ...

# Perch Runway
RewriteCond %{REQUEST_URI} !^/perch 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /perch/core/runway/start.php [L]

Have I not understood how routes work? This is the first time I've tried using them. I'd imagined that the settings in the URL pattern for the target page took care of this? Have I not fully understood how this works? If something else needed in .htaccess too? But why do all of them work now, except any with '( & )' in them?

Drew McLellan

Drew McLellan 2638 points
Perch Support

When you say:

The visitor is taken directly to the site's home page (/index), so there's no debug info to give you.

Does the page get routed by Runway or by your web server? I got the impression you were outside Runway at that point.

I believe its Runway that's doing it. I'm not aware of any reason for the web server to be doing it. Is there a way of checking this? Or trying something to prove it? The site is in development so I can try anything necessary.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Is the page you end up on served by Runway?

Yes it is. All the pages in the site are served by Runway.

Drew McLellan

Drew McLellan 2638 points
Perch Support

So how are you ending up on the homepage? What do you have in place to make that happen?

As described above, I think its the routing within Runway that's sending you there. Just this link causes it ...

https://dev.xxxxx.co.uk/businesses/builders+%28services+%26+contractors%29/5

If I change the link to https://dev.xxxxx.co.uk/businesses/builders+%28services%2Fcontractors%29/5 it works fine and sends you to the correct target page.

And links like these all work perfectly (just 3 shown here, but there are around 30 of them on the page) ...

https://dev.xxxxx.co.uk/businesses/architectural+services/65 https://dev.xxxxx.co.uk/businesses/cleaners+%26+cleaning+services/12 https://dev.xxxxx.co.uk/businesses/hairdressers+%26+barbers/7

Drew McLellan

Drew McLellan 2638 points
Perch Support

Is it issuing a redirect header?

Here's the logfile entries for 1) the failing link and 2) a link that works ...

82.71.57.159 - - [10/May/2017:18:01:49 +0000] "GET /businesses/builders+%28services+%26+contractors%29/5 HTTP/1.1" 302 219 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"
82.71.57.159 - - [10/May/2017:18:01:49 +0000] "GET / HTTP/1.1" 200 4870 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"

82.71.57.159 - - [10/May/2017:18:03:20 +0000] "GET /businesses/hairdressers+%26+barbers/7 HTTP/1.1" 200 4356 "https://dev.allaboutmagazines.co.uk/businesses" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36"

Drew McLellan

Drew McLellan 2638 points
Perch Support

So yes, it's issuing a 302. Do you know where that's coming from? What's on the page?

For anyone reading this thread, I gave up trying to fix this problem.

Drew McLellan

Drew McLellan 2638 points
Perch Support

You just need to find whatever it is you have on the page that is issuing the redirect to your homepage.

I've coded around the issue to remove the parentheses from the links, so the routing will always work. At the same time, I stripped out various other characters to clean up the URLs in the links and make them look tidier. We'll never know the cause of the problem.