0

I'm having an issue with case sensitivity in URL's. I have a template that includes a channel entries tag that loads a structure entry, a structure nav that starts from segment_1, and a {segment_1_category_id} tag. The entry for the page has a structure URI of /foo.

Loading site.com/foo produces the following result -

channel entries - correct entry
structure nav - correct nav
segment_1_category_id - correct cat id

Loading site.com/Foo produces the following result -

channel entries - correct entry
structure nav - loads the full top level structure nav, so {segment_1} doesn't match an entry
segment_1_category_id - no cateogry id

I tried using mod_speling to tell Apache to ignore case in URL's, but that doesn't seem to have worked.

Other solutions seem to be using php strtolower to clean up the URL's, but I'd have to hack a few places to do that or turn on php on templates, neither is desirable.

I could also use a .htaccess redirect to force all the URL's to be lowercase, but I don't love using a redirect, and I might run into issues with the redirect in other cases.

What am I missing here as a better solution? I haven't run into this before and as far as I can tell from google, it's not a common problem.

3
  • Is it due to doing a string comparison conditional in your template? If so, the web server can't intervene here unless it filters the path to lowercase and provides that modified path to PHP. If this is what is happening, I can update with an answer on using case-insensitive conditionals. – Derek Jones May 11 '16 at 1:54
  • No conditionals, the channel entries loop is picking up the correct entry with no entry id / url title parameter. The structure nav tag takes {segment_1} as a parameter for start from. {segment_1_category_id} is a standalone tag. – Jacob Russell May 17 '16 at 12:46
  • Ok, was hoping it was conditional based so you could do a case-insensitive regex, but it sounds like this may be a case-sensitive comparison in Structure's code. You could perhaps use a strtolower plugin on the Structure Nav tag parameter though? Are there bad links out there? Technically Foo.html and foo.html are two separate files on most of the file systems that run the web. Not sure it's possible but the best behavior might be to {redirect="404"} in the Structure Nav tag if segment_1 exists and there's no match. – Derek Jones May 17 '16 at 14:49
0

This looks like a bug in structure. Have a look at the nav function: ./structure/mod.structure.php around line 109

exp:structure:nav uses php's array_search() to locate your "start_from" value in structure's list of urls. ( $site_pages['uris'] )

A successful search sets $branch_entry_id to something other than 0 and structure builds your menu starting on that branch.

If search fails, the starting branch is 0 or / which loads everything.

We wanted /FOO, /Foo, /FoO and /foo to be the same entry so I added an additional check which looks again for an all lowercase version of start_from.

if($found_key === false)
    $found_key = array_search(strtolower($start_from), $site_pages['uris']);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.