GitHub Pages trailing slashes - jekyll

Using Middleman on GitHub Pages with directory_indexes enabled, I wonder if I can somehow get rid of the trailing slash GitHub adds.
My urls are basically: /foo-bar -> /foo-bar/index.html.
Visiting /foo-bar on GitHub Pages redirects to /foo-bar/.
Is there any way to prevent this redirect?

A "trailing slash" redirect is issued when the server receives a request for a
URL http://servername/foo/dirname where dirname is a directory. Directories
require a trailing slash, so mod_dir issues a redirect to
http://servername/foo/dirname/.
Source
The problem with this is that GitHub pages / Jekyll build the way you have shown
above. To fix this, foo-bar needs to be a file rather than a directory:
http://example.com/foo-bar.html
Then you should be able to do:
http://example.com/foo-bar
ยง Permalinks

Related

HTML file structure's affect on website URL

I currently have a simple website, hosted on github pages with a file structured in hierarchical directories as shown below:
/foobar.com
/css
/js
/images
/html
/news
/news_content
fizz.html
buzz.html
news.html
about.html
contact.html
index.html
However, when I am on the buzz webpage for example, this has resulted in the URL to become:
https://foobar.com/html/news/news_content/buzz.html
Is there a way to change this URL so that it doesn't show all the folder directories and instead, just the file itself i.e. https://foobar.com/buzz.html as I don't want to separate all the individual HTML files into separate folders?
Yes, you can change the URL to be more user-friendly by using server-side URL rewriting or client-side JavaScript.
For server-side URL rewriting, you'll need to use a web server such as Apache or Nginx and configure it to rewrite the URLs. You can find more information on how to do this for Apache or Nginx by searching for "URL rewriting" on their websites or forums.
For client-side URL rewriting, you can use JavaScript to manipulate the URL shown in the browser's address bar. However, this method may not be ideal for search engines or users who have JavaScript disabled.
If you are using GitHub Pages to host your website, you might be able to achieve URL rewriting by using Jekyll. Jekyll is a static site generator that supports URL rewriting and can be used in combination with GitHub Pages to host your website. You can find more information on how to do this by searching for "Jekyll URL rewriting."
How a URL is resolved to a resource depends on the HTTP server and/or the server side programming language you are using.
Github Pages provides no features that allow anything other than a direct reflection of the directory layout in the URL.
The closest you could come would be to write a program that transformed the input (the file structure you want to work with) into the file structure that Github Pages will express as the URLs you desire (and then run it as a build step that takes the pages out of your working branch and into your gh-pages branch; possibly you could use actions to do this).

Jekyll: Redirect from URLs containing colons

I am currently converting a MediaWiki site to Jekyll (GitHub Pages). Unfortunately, MediaWiki category pages have URLs containing a colon ":" :
http://www.example.com/Category:Name_Of_Category
I would like to redirect these old URLs to new Jekyll pages with URLs in the form of:
http://www.example.com/name_of_category/
Therefore, I used redirect_from in the front matter of name_of_category.md, but Jekyll fails to build as the generated static html file containing the redirect has a colon in the file name:
Error: Protocol error # rb_sysopen - /www.example.com/_site/Category:Category_Name.html
Encoding the colon results in the same error message. I tried:
redirect_from: /Category%3ACloud_Application_Architectures
redirect_from: /Category:Cloud_Application_Architectures
Finally, I included a file Category%3ACloud_Application_Architectures.html in the jekyll page folder. It is added to _site during build, but when browsing to http://www.example.com/Category:Category_Name a "Not Found" error is returned.
Any help would be greatly appreciated! Using a separate webserver with ProxyPass redirection to GitHub handling the redirects in the .htaccess file would only be my last resort. After all, I am trying to get rid of maintaining a server for the site ;-)

Jekyll/Github Pages -- index.html not being written?

Cross-posted in a Github issue at https://github.com/SeanKilleen/seankilleen.github.io/issues/189
Digging into an issue with GitHub pages that appears like it might be recent.
I noticed an up-tick in 404s via Google Analytics. It appears that posts with trailing slashes are becoming 404'd, but appeared just fine without the slash.
My local Jekyll instance generates the following structure for how-to-leave-a-company-well.md from Feb 2015:
/2015
/02
/how-to-leave-a-company-well.html
/how-to-leave-a-company-well
/index.html
So, the following URLs work just fine locally:
http://localhost:4000/2015/02/how-to-leave-a-company-well
http://localhost:4000/2015/02/how-to-leave-a-company-well.html
http://localhost:4000/2015/02/how-to-leave-a-company-well/index.html
http://localhost:4000/2015/02/how-to-leave-a-company-well/
Those last two URLs that I've bolded do not seem to exist on my published site after GitHub Pages generates the documents.
I cannot reach http://seankilleen.com/2015/02/how-to-leave-a-company-well/ or http://seankilleen.com/2015/02/how-to-leave-a-company-well/index.html
This seems to indicate to me that GitHub Pages is doing something differently than my Jekyll installation. Given that the 404 spike is recent, I'm wondering if there might have been a change related to this.
Does anyone have a thought on how I might be able to diagnose this? It's a bit of a black box for me when my local is doing what I expect and I can't see the Github Pages process.
Jekyll 3 changed the way the permalinks worked, and dropped the trailing slash if your permalink setup did not contain one - yours does not contain a trailing slash at the end of your permalink in the config file. Jekyll 3 now respects that and thus your page is a 404 when there is a trailing slash in the url (since you want it without it).
https://jekyllrb.com/docs/upgrading/2-to-3/#permalinks-no-longer-automatically-add-a-trailing-slash
You may want to check which version of jekyll you have installed - you may be on 2.x and GH is now 3.x
When working locally, are you telling jekyll to use the GH pages gem? if you
don't do this you may get different behavior on GH than local. I do not do this, so I can't tell you how to do it (or if this particular issue would happen), but I do know that you should do it if you want to preview locally what you will get when serving via GH.

Jekyll extension-less permalinks with markdown

From the Jekyll docs it says (using .md format):
Clean URLs can also be achieved using the permalink front matter variable. In the example above, using the first method, you can get URL http://example.com/other for the file other.md by setting this at the top of the file: permalink: /other
Here is an example my page front matter:
---
layout: page
title: Contact
permalink: /contact
---
Everything works fine when I'm using jekyll serve but when I build and upload to my static host it doesn't work. The file structure Jekyll outputs doesn't make sense for the functionality it claims from the docs.
.
|-- css/
|-- index.html # => http://example.com/
โ””โ”€โ”€ contact.md # => http://example.com/contact.html
I want to be able to go to http://example.com/contact and have it show contact.md. I know I could have similar functionality by manually putting my files in folders (and then renaming them all to index.html) like it says in the docs here, but I don't want to have to go through the extra step and I don't prefer the trailing / e.g. http://example.com/other/.
I am using Jekyll 3.0.1
I have found these questions but they don't address the problem I'm facing.
How to link to a page with page.url without the html extension in Jekyll?
How to make all posts have a permalink with custom format "domain.com/blog/title"?
Can Jekyll omit index.html from folder URLs?
I am also using clean permalink in my jekyll blog.
Here is my frontmatter:
---
layout: directory
title: About
permalink: about/
---
Got any different? , it is trailing slash at the end of URL. I know, you don't want to see any trailing slash at the end of URL, but for that you need to use nginx, because Jekyll generate all post/page like this /folder/index.html.
I think you are doing it correctly, it is just a matter of configuring your webserver properly (assuming it supports removing the extension). It works properly locally cause the built in jekyll webserver can do it by default. The docs have info on this here:
http://jekyllrb.com/docs/permalinks/#extensionless-permalinks
On AWS S3 it says you can host with extensionless urls by uploading files with no extension at all, and then setting the content type to text/html. I don't think it is possible to get jekyll to output contact.html as just contact with no extension. So you get the web server to remove the extension, if it supports that (on s3 I use the trailing /).
This has some interesting info too:
https://github.com/jekyll/jekyll/issues/3345

GitHub Pages (github.io) doxygen generated page not found (404)

I don't understand why a page generated by doxygen can't be found (404).
Its path in the Github repository is https://github.com/AubinMahe/AubinMahe.github.io/blob/master/doxygen/html/dd/dfb/_shareable_8h.html Click here to see
The same page browsed from the root of dcrud documentation site is http://aubinmahe.github.io/doxygen/html/dd/dfb/_shareable_8h.html Click here to see
The same path but... 404! Why? Why this page and not the others?
I've found an answer...
Files that start with an underscore are missing
By default, Jekyll does not build any files or directories that
are hidden or used for backup
(indicated by names that start with . or #, or that end with ~);
contain site content (indicated by names that start with _); or
are excluded in the site configuration.
To work around this behavior, you can
include a .nojekyll file in the root path to turn off Jekyll;
use the include directive in your _config.yml to specify files that
should not be ignored; or
do not use file or directory names that start with an underscore (_),
period (.), or hash symbol (#), or that end with a tilde (~).