Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jekyll redirect link

I moved my site http://www.phonations.com to Jekyll/GitHub pages.

Before that, I knew how to redirect some urls on my site to external ones. How to do that now?

For example, I would like http://www.phonations.com/tmwtga to redirect to https://www.dropbox.com/s/tw1b0kvoc75c7lx/tmwtga.zip?dl=0 or some other url (using git lfs).

While the plugin "jekyll-redirect-from" allows redirecting a path to a page, it does not seem to allow redirecting a path to another kind of resource.

like image 664
Martin Delille Avatar asked Sep 23 '16 09:09

Martin Delille


People also ask

How do I redirect on Jekyll?

JekyllRedirectFrom can be used to setup multiple redirects for a URL on jekyll sites. All you need to do is add the jekyll-redirect-from gem to your jekyll project and add a redirect_from in the YAML front matter of post or a page to specify the older locations from which the current location is mapping to.

How do I redirect a HTML page to another HTML page?

To redirect one HTML page to another page, you need to add a <meta> tag inside the <head> section of the old HTML page. The <head> section of an HTML document contains metadata that is useful for the browser, but invisible to users viewing the page.

How do I redirect a github page?

The redirect is accomplished with a <meta> tag. By setting the http-equiv attribute to refresh and the content attribute to 0; URL=https://example.com/ we will redirect the user to 'https://example.com/'.


2 Answers

That plugin does allow for redirecting to external URLs. To redirect your example URL, create a file called tmwtga.html and add the following front matter:

---
permalink: /tmwtga
redirect_to:
  - http://www.example.com
---

Assumes your server supports extensionless URLs (in this case GitHub Pages does). You might not need the permalink, but I put it in there in case you have a default set in _config.yml.

Source: https://github.com/jekyll/jekyll-redirect-from#redirect-to

like image 117
Ross Avatar answered Oct 25 '22 00:10

Ross


In case

  • it is OK to use the wrong HTTP response code (200 OK instead of 301 Moved Permanently),
  • you are hosted in GitHub pages,
  • you want to rely on the build-in features, and
  • you do not want to use GitHub workflows for building and pushing to gh-pages then

you can do following:

  1. Create file _layouts/redirect.html:

     <html>
     <head>
         <meta charset="utf-8"/>
         <meta http-equiv="refresh" content="1;url={{ page.redirect }}"/>
         <link rel="canonical" href="{{ page.redirect }}"/>
         <script type="text/javascript">
                 window.location.href = "{{ page.redirect }}"
         </script>
         <title>Page Redirection</title>
     </head>
     <body>
     If you are not redirected automatically, follow <a href='{{ page.redirect }}'>this link</a>.
     </body>
     </html>
    
  2. For each page, you want to redirect from, use following content:

     ---
     redirect:   https://www.example.org
     layout:     redirect
     ---
    

The HTML code is an extention to the HTML code provided by a tutorial by W3C.

like image 36
koppor Avatar answered Oct 24 '22 23:10

koppor