How to make github pages url case insensitive?
Asked Answered
F

3

12

Website works for
jerrygoyal.github.io/Flash-Clipboard

but not for (404 error):
jerrygoyal.github.io/flash-clipboard
jerrygoyal.github.io/FLASH-clipboard
jerrygoyal.github.io/flaSH-CLIPboard and so on
You get the idea! How can I make the url case-insensitive?

I've never worked on Jekyll and not sure if my project pages are using jekyll or not. I only created an index.html page and put inside the docs folder of the repository.

I'm using a custom domain (www.jerryfactory.com) to map jerrygoyal.github.io


Here's the URL to my Github Organisation site : https://github.com/JerryGoyal/jerrygoyal.github.io

And URL for my Github project site: https://github.com/JerryGoyal/Flash-Clipboard/tree/master/docs

I'm thinking of moving my project site content to my Github Organisation site if it's possible. So if the URL case insensitivity works for only Organisation site it's fine.


Ref: Org and Project Site in Github

Froehlich answered 22/1, 2018 at 18:29 Comment(2)
Check this: #25816454Signorino
You could setup redirects for the case sensitivity that you want redirected to the main URL to mimic the behavior you want.Joshua
S
9

There is no direct way to make github page URLs case-sensitive. But, you can use following hack:-

Redirect from 404 page with mixed-case or upper-case URL to lower case URL. Steps to achieve this:-

  • Just go to your root repo (your_username.github.io).
  • If not already exist then create a 404.html file and add the following script in it.
<script>
    window.onload = () => {
        currentURL = window.location.href;
        lowerCaseURL = currentURL.toLowerCase();
        if (currentURL != lowerCaseURL) {
            location.replace(lowerCaseURL);
        }
    };
</script>

Note:- Make sure your pages/repo name are always in lower-case.

Logic explained with example:-

If your URL is:-

anmol53.github.io/bmi-tracker

and someone tried following URL:-

anmol53.github.io/BMI-Tracker

By default he/she will get 404. Now we will redirect him/her to anmol53.github.io/bmi-tracker by changing case of current URL by using above script.

Samirasamisen answered 6/8, 2022 at 22:57 Comment(1)
ngl that's a sweet hackFroehlich
P
17

How can I make the url case-insensitive?

The short answer is: You cannot / It's not possible in GitHub Pages as of this writing.


The long answer is: Having URLs case-sensitive is a web standard and most webservers will respect that. This has nothing to do with Jekyll or any other similar tool. It's a responsibility of the webserver that is serving the HTML pages that were generated by Jekyll, and in the case of GitHub Pages, they use a *nix-based webserver that is compliant with case-sensitive URLs when locating resources.

A common way to solve this problem is to make sure your pages in Jekyll are always lower-case, which in turn will generate lower-cased URLs.

This shouldn't really be a problem, unless your users are typing the URLs by themselves... And in that case, if you want to be proactive, you can use the jekyll-redirect-from plugin and create redirect entries of the most common ways you believe users will try to access each page.

For example, having the main URL as

  • augustoproiete.github.io/flash-clipboard

and redirect the ones below to the main one above via jekyll-redirect-from

  • augustoproiete.github.io/Flash-Clipboard
  • augustoproiete.github.io/FLASH-CLIPBOARD
Planoconvex answered 22/1, 2018 at 20:9 Comment(7)
as i've mentioned in the question that i've no knowledge about the jekyll. would you mind telling how to do this change?Froehlich
@JerryGoyal All the instructions on how to configure it are in the README of the jekyll-redirect-from plugin - github.com/jekyll/jekyll-redirect-fromPlanoconvex
that README has some installation steps which I don't understand so i followed the steps given in help.github.com/articles/redirects-on-github-pages and it didn't work.Froehlich
Are you sure that redirect-form would work for custom static pages?Froehlich
Yep... It works for pages, posts, collection items, etc. If you put a reproducible example on GitHub, I might be able to more easily point out what's missing. BTW, here is an example of a Jekyll site that uses the jekyll-redirect-from plugin and works fine: github.com/netponto/netponto.github.ioPlanoconvex
this is my organization site for mail URL: github.com/JerryGoyal/jerrygoyal.github.io and this is my project site for URL/Flash-Clipboard github.com/JerryGoyal/Flash-Clipboard/tree/master/docsFroehlich
The redirect plugin will not be able to redirect differently cased URLs, because it faces the same constraint of Github not differentiating between case.Bastard
S
9

There is no direct way to make github page URLs case-sensitive. But, you can use following hack:-

Redirect from 404 page with mixed-case or upper-case URL to lower case URL. Steps to achieve this:-

  • Just go to your root repo (your_username.github.io).
  • If not already exist then create a 404.html file and add the following script in it.
<script>
    window.onload = () => {
        currentURL = window.location.href;
        lowerCaseURL = currentURL.toLowerCase();
        if (currentURL != lowerCaseURL) {
            location.replace(lowerCaseURL);
        }
    };
</script>

Note:- Make sure your pages/repo name are always in lower-case.

Logic explained with example:-

If your URL is:-

anmol53.github.io/bmi-tracker

and someone tried following URL:-

anmol53.github.io/BMI-Tracker

By default he/she will get 404. Now we will redirect him/her to anmol53.github.io/bmi-tracker by changing case of current URL by using above script.

Samirasamisen answered 6/8, 2022 at 22:57 Comment(1)
ngl that's a sweet hackFroehlich
V
0

You can’t make it case-sensitive. Sorry. Case-sensitive URLs are a web-standard. It would be cool if URLs were case-insensitive, but that isn’t true.

Verne answered 27/1, 2018 at 19:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.