Jump to content
EvanFreyer

URL Segments and Umlauts throw 404

Recommended Posts

Hey there,

I have a problem with URL Segments and Umlauts in it. I want to grab the a segment of the url and use it as a parameter to find a something in Processwire. The problem is, that if I input an umlaut into the url, processwire immediately throws a 404 error page and I am not able to transform my inputs.

Is there a way to get around that problem?

Cheers,

Evan

Share this post


Link to post
Share on other sites

Some code or screen would make shure that you've get the right answer.

- Where you put umlauts in which input (frontend form ->Code example?)

- How do you use the url segment code example

- are you using the name attribute of the $page and not the title?

...regards mr-fan

Share this post


Link to post
Share on other sites

@EvanFreyer, open your .htaccess file and look for this line:

# OPTIONAL: Send URLs with non name-format characters to 404 page

This is the first step at enabling non-ascii URLs, though I'm not entirely sure if it's the only one you need to change.

  • Like 4

Share this post


Link to post
Share on other sites

@teppo: Thanks for the info! I removed the redirection and now I can access the page. However, it seems to strip umlauts from the url. I haven't found that option yet.

@mr-fan: Code examples are not relevant right now. I added a template and allowed URL Segmentation. I don't have any rules set up at all, so it just accepts it. Until now, an Umlaut leads to the default 404 page and the code of the template was not executed at all.

With teppo's changes to the htaccess (I should have known that, damn... thanks again ;)), the page is at least called. Now I have to search, where processwire or the htaccess strips my Umlauts.

Share this post


Link to post
Share on other sites

Umlauts are not supported (see processwire's page-name restriction) and somewhere on the forums did Ryan give a statement about that fact, but I don't remember where it was. 

Share this post


Link to post
Share on other sites

One hacky solution would be parsing the URL manually from $_SERVER['REQUEST_URI']. It's nowhere near as clean and simple as checking $input->urlSegment1, you'll have to route these requests through your home page each and every time, and it won't be a valid solution for all use cases.. so perhaps not the best thing to do after all :)

Somehow I was under the impression that URL segments wouldn't be as "strict" as actual URLs, no idea where I got such idea.

Share this post


Link to post
Share on other sites

I thought, URL Segments are not part of the page-name restrictions as well since I only saw them as an alternative to GET-parameters. I changed the programming, so that it will search for an ID rather than the title of something, so that still works, but the URL is not as pretty.

But just for the sake of discussing things: If I integrate a tagging system for news and if I like to have some kind of overview of all news by a certain tag, I was under the impression, that I can use URL Segments to indicate which tag I was searching for. Since all Tags would be unique, the name alone could be my identifier. Do I have to use GET-Parameters, if I wanted to do it the "PW-way", since something like news/bytag/ÄÖÜ is not supported?

I hope, I made myself clear, I can be a little bit confusing ;).

Share this post


Link to post
Share on other sites

Here you've the statement from Ryan about this: https://processwire.com/talk/topic/580-encrypted-urlsegment/?p=4652

@Evan

Most likely you're tags will be created as pages, therefore they'll already have a pageName. Just use this as urlSegment and you're good to go. If you want to use the new options fieldtype you could instead use the value|Label syntax.

E.g: A german tag "Männer" would could get the name "maenner" (Page) or be defined as option like this: "1=maenner|Männer". Both would work for this url: example.com/tags/maenner/

  • Like 2

Share this post


Link to post
Share on other sites

I ran into some problems while developing, perhaps someone could help me?

I am trying to use the pageName as the identifier right now and everything works, but $page->name always returns the english page name and not the localized. I fixed that with using $page->localName($user->language). However, my selector does not seem to work that way. It seems as if it does not find the local value. I am using $page->find("name=".$sanitizer->selectorValue($localName)). The English version works flawless.

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 louisstephens
      So I have been hard at work creating url segments for a template (api) and everything is working swimmingly in creating a simple end point for svelte.js. I have however, run into a few questions that I can wrap my head around.
      In my api template I have:
      if($input->urlSegment1 === 'clients') { header('Content-Type: application/json'); $clients = $pages->find("template=clients"); $client_array = array(); foreach ($clients as $client) { $id = $client->id; $title = $client->title; $url = $client->url; $clientName = $client->client_name; $clientColor = $client->client_color->value; $assigned = $client->assigned_to->user_full_name; $client_array[] = array( 'id' => $id, 'code' => $title, 'name' => $clientName, 'associated_users' => $assigned, 'url' => $url ); } $client_json = json_encode($client_array, true); echo $client_json; } The output json from this is:
      [ { "id":1644, "code":"abc", "name":"Test Name", "associated_users":null, "url":"\/pw\/clients\/abc\/" }, { "id": 1645, "code": "xyz", "name": "Test Name", "associated_users": null, "url": "\/pw\/clients\/xyz\/" }, ] I was curious is it possible to add in "clients" before this output json so it would appear as 
      clients: [ { "id":1644, "code":"abc", "name":"Test Name", "associated_users":null, "url":"\/pw\/clients\/abc\/" }, { "id": 1645, "code": "xyz", "name": "Test Name", "associated_users": null, "url": "\/pw\/clients\/xyz\/" }, ] I was not really sure of how to tackle this in my php code, and have spent more time than I care to admit trying to figure it out. Another question I have is that "associated_users" is returning null, which in this instance is correct. It is a multi page field that is set to pull a custom name field from the users template, ie "Louis Stephens" would be associated with the first page. I understand that I need to use a foreach to get the correct data, but I was really unsure of how to place this inside an array, or update the array with the new data. Any help with any of this would greatly be appreciated.
    • By Moritz Both
      Greetings!
      For our PW project we use markup regions and, for one template, url segments. The documentation recommends throwing a new Wire404Exception() from the template when the code concludes that the url segments from the request are invalid, and so we do.
      However, the 404 page is not displayed properly. Viewing the page source in the browser we can see that the original, unmodified markup region contents from our _init.php file is prepended to the correct html output, messing the whole page up.
      Any advice is greatly appreciated.
    • By hansv
      Hi everybody
      I want to catch a variable from outside processwire into _main.php
      if(isset($_GET['u']) && $_GET['u'] !== ''){ $gebruikersnaam = $_GET['u']; ... ... This is working fine in a php file in a non processwire environment. 
      In a processwire environment, I get the variable when I refer to /site/templates/_main.php but a great part of my template-code is not shown. 
      From outside processwire I refer to    mydomain/index.php.  If I place   $gebruikersnaam = $_GET['u'];  in index.php, how can I pass through my variable to _main.php?   Or is there an other solution?
      thx
      hansv
    • By louisstephens
      So I have a project coming up soon and one of the goals was to use Google's AMP project for the project's mobile site. I have gone through the tutorials and think I have a good grasp on the matter, but there is still one roadblock I do not really know how to tackle. The site, which uses a responsive grid system, will look great on a mobile and desktop which was is fine by me. However, if a user comes from Google to one of our AMP pages (ie www.example.com/amp) and clicks on a url, they will then be loading our responsive mobile pages and not the amp pages. For the sake of consistency, we really want to "force" users to stay on all the amp pages.
       
      My current thoughts on how to set up this task:
      Allow url segments for all pages using "/amp" Using a simple if statement, load the amp page if it exists <?php if($input->urlSegment1) { // add "&& $input->urlSegment1 == 'amp'" if you've more urlSegments include("partials/amp-page.php"); } else { include("partials/normal.php"); } ?>  
      However, I have hit a roadblock on appending "/amp" to all pages if they came to an amp page via Google, or even if they are on mobile and visit the site. Is this even possible to do, or should we just use the amp pages (if a user comes from google) and allow them to be active on our mobile pages?  We are just trying to give the fastest load times possible, as well as give a consistent look between mobile and desktop versions. As always, I really appreciate the ideas and help.
    • By Pixrael
      I have a parent page (with template file) with several child pages (without template file) that are hidden and unpublished, I use them only to store information. The parent page have the url segments enabled.
      When I catch the segment in the template file, works as expected for any word, but if the url segment match the property "name" of any child page, PW launch a 404 Page Not Found.. I try all combination of "hidden" and "Publish" for the child pages.
      The idea is to render the data from the parent page plus the data of a child page, and get this data using an url segment (links generated dynamically) with the same name that this hidden page have.. I don't like having a template file for these child pages that only execute the render of the parent page with the information .. I want the previous solution if it possible
      I was able to explain well? ...What happen here?
×
×
  • Create New...