Jump to content

URL encoding of URL Segments possible?

Recommended Posts

A client wants to use landing pages coming from Google ads, and needs to hand over a keyword and a title for the landing page.

The URL would look like this: ..../l2/keyword/Funny title with løts of special chåracters änd spaces/ (Just an example)

I tried to encode the URL in different ways but not even spaces work and result in a "404 Page not found".

Then I found this Github issue: https://github.com/processwire/processwire-issues/issues/720
At least I know that I am not the only one with this kind of problem.

The client is a very pragmatic fellow and suggested to custom-encode the segments like: (don't try to read it)
and then replace all the _S_ _a2_ with the REAL characters in the template.

Mhh... well... sure I could do that, but I don't like it, and editors would have to write the segments with a translation sheet!

Anyone have a better idea?

PW 3.0.98 PHP 7.x

Share this post

Link to post
Share on other sites

Do you really need it human readable? In this case GET and urlencode() is maybe a safer option.

$query = "?keywords=" . urlencode('løts of special chåracters änd'); // "?keywords=l%C3%B8ts+of+special+ch%C3%A5racters+%C3%A4nd"

$keywords = urldecode($input->get->keywords);  // "løts of special chåracters änd"


  • Like 2

Share this post

Link to post
Share on other sites


The problem is that editors would have to write this in a Google tool?(I don't know...) and I can't urlencode it in a template.
Perhaps I write a tool for them or they use an online tool for the encoding.

But GET parameter seem the better option.

  • Like 1

Share this post

Link to post
Share on other sites

Sometimes I wonder how I tie my shows in the morning... thinking way too complicated 😁
So many years and I love Processwire even more every day!

Everything I need is already there. I do it in the backend with two fields(text) and FieldtypeRuntimeMarkup generates urlencode($page->encodekey)) and so on... and the result is the complete URL for the editors to copy. And even a button to test it!

$prefix = $page->httpUrl . '?';
$l_key = urlencode($page->encodekey);
$l_title = urlencode($page->encodetitle);
$gclid = '123456789';
$result = '<textarea rows="5">'.$prefix . 'keyword=' . $l_key . '&title=' . $l_title . '&gclid=' . $gclid . '</textarea>';
return $result;


  • Like 2

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By pwFoo
      With JS fetch() it is a bit tricky to get for example $_POST populated (params need to be FormData / forms), but would it possible to get PW $input (get, post, urlSegments, queryString) working for fetch requests?
      Is there a fix / hook / workaround to solve it PW side?
    • By Vigilante
      I have segments turned on for the root/home page. This is because I'm doing some custom routing to remove a path from the URL.
      One of the grandchild pages itself has segments turned on.
      So when I'm doing my custom routing from the home page, I look to see if the URL is valid by using a standard get lookup on the segment string. Something like `$pages->get("/myroute/".$input->urlSegmentStr()."/");`
      The problem is, the segment string may have a path that itself includes segments, like "/route/allows-segments/segment".
      So get() returns nothing, essentially going to 404, because it can't find that path which has a segment in it.
      Is there a way to make get() smart enough to see that even though /segment/ isn't found as a page, its parent /allows-segments/ has segments turned on and thus it can get that page instead?
      I already programmed my workaround, it's not that big of a deal. I had to specifically test for the segmented URL though. Luckily I only have one page like this, but I can see it being an issue if I had a lot of them.
      Perhaps get() needs some kind of options (or another finder function entirely) that can deal with paths with segments. Where it will process the path and check for segments, returning the proper page.
    • By ttttim
      I have a parent page containing a list of it's children. When you click on one of the children the page opens up in a modal box trough ajax. So far so good. 
      But if i directly load the page through the url (parent/child) i get the child page. Is there a way of loading the parent page instead with the child page opened inside the modal box? I was first thinking of using URLSegments so it would load the parent page with the child name as segment however since the segment is an actual page it will load the page instead.
      Any ideas?
  • Create New...