54

I understand that .htaccess is not supported by GitHub Pages. Is there an alternative for password-protecting particular directories for websites hosted by GitHub Pages?

6
  • 5
    but the directories are open source unless its in a private repo?
    – comp500
    Jan 16, 2013 at 6:49
  • 2
    you're right about that... but assuming one has a private repo...
    – hatmatrix
    Jan 19, 2013 at 12:48
  • yeah... they should add a similar function to .htaccess
    – comp500
    Jan 19, 2013 at 13:06
  • 1
    The exact same question has been asked ok Webapps.stackexchange: webapps.stackexchange.com/q/35692/8562 Jan 9, 2014 at 5:32
  • @MartinThoma probably 'cause he asked it.
    – MD XF
    Oct 31, 2016 at 21:07

5 Answers 5

16

Although you can't use .htaccess or .conf, Github has instructions on how to use the Jekyll Redirect From plugin.

https://help.github.com/articles/redirects-on-github-pages/

The page above no longer has any mention of the plugin. The direct link to the jekyll-redirect-from plugin GitHub repo is https://github.com/jekyll/jekyll-redirect-from

1
  • 1
    Does this plugin allow for external redirects? In my .htaccess I had Redirect /PDF https://drive.google.com/file/d//view?usp=sharing
    – PovilasID
    Oct 25, 2017 at 13:53
11

"Unfortunately, GitHub pages only supports static pages. There is no way to make it execute server-side code and thus it's impossible to protect your pages with any kind of authentication scheme. If you expand further on why you need to password-protect your pages, maybe I can help you find a workaround."

Source: https://webapps.stackexchange.com/questions/35692/is-there-an-alternative-to-using-htaccess-to-password-protect-subdirectories-in

1
  • 1
    I am here since I needed a git hub page to redirect based on the google API not liking Angular App hashtag URL. Now since I cant control the redirect I will need to host the App myself - unless I can get around the Google Console API somehow...
    – landed
    Jan 23, 2014 at 13:35
6

This post comes out at the top of web search when you look for .htaccess redirects in github pages. I am going to answer this question in that sense.

One option is to use a DNS redirect instead. You do this by putting a file named CNAME in the project's root directory (not sure if it works in a subdirectory). Just put the redirection URL in the file. However, there are a few limitations, e.g. you can only redirect to a website's root.

2
  • 1
    please provide an example
    – Atais
    Aug 26, 2020 at 10:48
  • @Atais, you can use DNS CNAME / DNS Synthetic records to do this.
    – DxTx
    Dec 10, 2020 at 17:53
5

I'm using a 404.html to redirect users from old S9Y index.php to my new blog on Github Pages. Check this commit: https://github.com/lionello/lionello.github.io/commit/c175f6524a53e29aea1890c8a758afd0e8944852

1

The answer is yes you can now add "404.html" in you code Repository. You can display a custom 404 error page when people try to access nonexistent pages on your github site.

For more information you can refer to this link!

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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