OBOFoundry.github.io icon indicating copy to clipboard operation
OBOFoundry.github.io copied to clipboard

Add 404 page with case insensitivity hack

Open erik-whiting opened this issue 2 years ago • 4 comments

This PR adds a 404.html page, which in itself will dictate how navigation to URLs of non-existent resources are handled. As of right now, if a user tries to go to a non-existent webpage, they'll see the GitHub Pages default 404 page. If this PR is merged, this file will now be what the user sees instead.

That said, this adds a hacky script to simulate case-insensitive URLs as requested in #1728. In general, case-insensitivity in URLs is not possible in GitHub pages since they run on Linux servers where case matters. To work around this, the 404 page will now take the given URL, cast it to an all lowercase URL, and then redirect the user to the all lower case URL if they don't match, simulating case insensitivity.

I want to highlight that this is a hack. Without access to the web server's .htaccess file (or whatever equivalent server configuration file), I don't think you can do redirects "the right way." Also, as mentioned in the comment, this code may cause the 404 page to be loaded twice. Suppose a user went to homepage/NonExistent.html, leading them to the 404 page, the script would redirect them to homepage/nonexistent.html which would again lead them to the 404 page. This hack also means that you have to make sure every page's file name is all lowercase from now on because this script will not work for pages that are called something like MixedCase.md.

Alternatively, there is a gem that handles redirects in Jekyll, but I think to use it, you'd have to add a redirect entry on every ontology page for every permutation of the ontology's name (e.g., for chebi, you'd have to make an entry for CHEBI, cHEBI, chEBI, cheBI, etc) to simulate true case insensitivity.

If you want to test this locally, try going to localhost:5000/ontology/CHEBI (or whatever address you have pointed at your local setup) and see that it redirects you to localhost:5000/ontology/chebi. If you're on Windows like me, the ontology/CHEBI URL won't be a problem because Windows apparently doesn't care about case. To test this, I put the following line right above window.onload() = () => { :

console.log("Hey! I'm at ", window.location.href);

I then went to localhost:5000/aSdF and saw the following output in the JavaScript console:

> Hey! I'm at localhost:5000/aSdF
. . .
> Hey! I'm at localhost:5000/asdf

Again, this implementation is a hack so consider if supporting case-insensitive URLs is more important than having clean, professional looking code.

erik-whiting avatar Oct 02 '22 03:10 erik-whiting

Hi @erik-whiting thanks for giving this a try. I didn't respond earlier because I'm not really sure what I think about this. For sure this is hacky and that makes me hesitant. Maybe there's a better way using permalink aliases in jekyll like https://talk.jekyllrb.com/t/multiple-permalinks-aliases/3705, but I don't know how big the actual need is here. I guess one problem is the mismatch between lowercased ontology IDs and the things that show up in PURLs

cthoyt avatar Oct 09 '22 15:10 cthoyt

I’m also a bit hesitant (but thankful for the work), do we know that users are frequently getting case wrong?

On Sun, Oct 9, 2022 at 8:43 AM Charles Tapley Hoyt @.***> wrote:

Hi @erik-whiting https://github.com/erik-whiting thanks for giving this a try. I didn't respond earlier because I'm not really sure what I think about this. For sure this is hacky and that makes me hesitant. Maybe there's a better way using permalink aliases in jekyll like https://talk.jekyllrb.com/t/multiple-permalinks-aliases/3705, but I don't know how big the actual need is here. I guess one problem is the mismatch between lowercased ontology IDs and the things that show up in PURLs

— Reply to this email directly, view it on GitHub https://github.com/OBOFoundry/OBOFoundry.github.io/pull/2124#issuecomment-1272569212, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAMMOPRIUOMKEEESUQQ4MTWCLR25ANCNFSM6AAAAAAQ2XDTKI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

cmungall avatar Oct 10 '22 14:10 cmungall

I’m also a bit hesitant (but thankful for the work), do we know that users are frequently getting case wrong?

I'm not sure about users getting case wrong, this is just in response to the issue here: https://github.com/OBOFoundry/OBOFoundry.github.io/issues/1728 which says to make pages case-insensitive. The PR simulates case insensitivity in the general case but if you wanted to, for example, just redirect all requests for <host>/CHEBI to <host>/chebi (while letting something like <host>/CHebi return 404), the jekyll-redirect-plugin would probably be a better solution. You could also identify other ontologies that are prone to being typed in all caps and we could add redirects to each one as needed.

erik-whiting avatar Oct 10 '22 15:10 erik-whiting

Hah, looks like I wrote that issue!

On Mon, Oct 10, 2022 at 8:10 AM Erik Whiting @.***> wrote:

I’m also a bit hesitant (but thankful for the work), do we know that users are frequently getting case wrong? … <#m_2875709819423157833_> On Sun, Oct 9, 2022 at 8:43 AM Charles Tapley Hoyt @.> wrote: Hi @erik-whiting https://github.com/erik-whiting https://github.com/erik-whiting https://github.com/erik-whiting thanks for giving this a try. I didn't respond earlier because I'm not really sure what I think about this. For sure this is hacky and that makes me hesitant. Maybe there's a better way using permalink aliases in jekyll like https://talk.jekyllrb.com/t/multiple-permalinks-aliases/3705 https://talk.jekyllrb.com/t/multiple-permalinks-aliases/3705, but I don't know how big the actual need is here. I guess one problem is the mismatch between lowercased ontology IDs and the things that show up in PURLs — Reply to this email directly, view it on GitHub <#2124 (comment) https://github.com/OBOFoundry/OBOFoundry.github.io/pull/2124#issuecomment-1272569212>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAMMOPRIUOMKEEESUQQ4MTWCLR25ANCNFSM6AAAAAAQ2XDTKI https://github.com/notifications/unsubscribe-auth/AAAMMOPRIUOMKEEESUQQ4MTWCLR25ANCNFSM6AAAAAAQ2XDTKI . You are receiving this because you are subscribed to this thread.Message ID: @.>

I'm not sure about users getting case wrong, this is just in response to the issue here: #1728 https://github.com/OBOFoundry/OBOFoundry.github.io/issues/1728 which says to make pages case-insensitive. The PR simulates case insensitivity in the general case but if you wanted to, for example, just redirect all requests for /CHEBI to /chebi (while letting something like /CHebi return 404), the jekyll-redirect-plugin would probably be a better solution. You could also identify other ontologies that are prone to being typed in all caps and we could add redirects to each one as needed.

— Reply to this email directly, view it on GitHub https://github.com/OBOFoundry/OBOFoundry.github.io/pull/2124#issuecomment-1273461419, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAMMOO5BI7TI6C77JCKMRTWCQWWTANCNFSM6AAAAAAQ2XDTKI . You are receiving this because you commented.Message ID: @.***>

cmungall avatar Oct 10 '22 15:10 cmungall