Programing

Jekyll 및 GitHub 페이지에서 이전 페이지를 리디렉션하는 가장 좋은 방법은 무엇입니까?

crosscheck 2020. 10. 30. 07:43
반응형

Jekyll 및 GitHub 페이지에서 이전 페이지를 리디렉션하는 가장 좋은 방법은 무엇입니까?


github 페이지에 블로그가 있습니다-jekyll

URL 전략 마이그레이션을 해결하는 가장 좋은 방법은 무엇입니까?

공통적으로 모범 사례는 이렇게 htaccess를 만드는 것입니다.

Redirect 301 /programovani/2010/04/git-co-to-je-a-co-s-tim/ /2010/04/05/git-co-to-je-a-co-s-tim.html

그러나 Github에서는 작동하지 않는 것 같습니다. 내가 찾은 또 다른 해결책은 리디렉션 페이지를 생성하는 레이크 작업을 만드는 것입니다. 그러나 HTML이기 때문에 301헤드 를 보낼 수 없으므로 SE 크롤러는이를 리디렉션으로 인식하지 못합니다.


가장 좋은 해결책은 <meta http-equiv="refresh"<link rel="canonical" href=

그것은 매우 잘 작동하며 Google Bot은 위치를 잃지 않고 새 링크 아래에서 전체 웹 사이트의 색인을 다시 생성했습니다. 또한 사용자는 즉시 새 게시물로 리디렉션됩니다.

<meta http-equiv="refresh" content="0; url=http://konradpodgorski.com/blog/2013/10/21/how-i-migrated-my-blog-from-wordpress-to-octopress/">
<link rel="canonical" href="http://konradpodgorski.com/blog/2013/10/21/how-i-migrated-my-blog-from-wordpress-to-octopress/" />

를 사용 <meta http-equiv="refresh"하면 각 방문자가 새 게시물로 리디렉션됩니다. Google Bot의 경우 <link rel="canonical" href=301 리디렉션으로 처리 되며 그 결과 페이지의 색인이 다시 생성되고 원하는 결과를 얻을 수 있습니다.

내 블로그를 Wordpress에서 Octopress로 옮기는 전체 과정을 설명했습니다. http://konradpodgorski.com/blog/2013/10/21/how-i-migrated-my-blog-from-wordpress-to-octopress/#redirect-301-on-github-pages


Jekyll Alias ​​Generator 플러그인 을 사용해 보셨습니까 ?

게시물의 YAML 머리말에 별칭 URL을 넣습니다.

---
  layout: post
  title: "My Post With Aliases"
  alias: [/first-alias/index.html, /second-alias/index.html]
---

사용자가 별칭 URL 중 하나를 방문하면 메타 태그 새로 고침을 통해 기본 URL로 리디렉션됩니다.

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
    <meta http-equiv="refresh" content="0;url=/blog/my-post-with-aliases/" />
  </head>
</html>

주제에 대한 이 블로그 게시물참조하십시오 .


이 솔루션을 사용하면 .htaccess를 통해 실제 HTTP 리디렉션을 사용할 수 있습니다. 그러나 .htaccess와 관련된 어떤 것도 GitHub 페이지에서 작동하지 않습니다. 왜냐하면 Apache를 사용하지 않기 때문입니다.

2014 년 5 월부터 GitHub 페이지는 리디렉션을 지원 하지만 jekyll-redirect-from Gem 문서 에 따르면 리디렉션이 발생하기 전에 전체 페이지로드가 필요한 HTTP-REFRESH ( <meta>태그 사용 )를 기반으로 합니다.

나는 <meta>접근 방식이 마음에 들지 않기 때문에 사전 생성 된 Jekyll 사이트를 제공하는 Apache를 사용하여 .htaccess 파일 내에서 실제 HTTP 301 리디렉션을 제공하려는 모든 사람을위한 솔루션을 만들었습니다.


먼저 속성에 추가 .htaccess하십시오 include._config.yml

include: [.htaccess]

다음으로, .htaccess 파일을 만들고 YAML 머리말 을 포함해야합니다 . 이러한 대시는 이제 Jekyll이 Jekyll의 템플릿 언어 인 Liquid로 파일을 구문 분석하기 때문에 중요합니다.

---
---
DirectoryIndex index.html

RewriteEngine On
RewriteBase /

...

리디렉션이 필요한 게시물에 다음과 같은 두 가지 속성이 있는지 확인하세요.

---
permalink: /my-new-path/
original: blog/my/old/path.php
---

이제 .htaccess에서 루프를 추가하십시오.

{% for post in site.categories.post %}
  RewriteRule ^{{ post.original }} {{ post.permalink }} [R=301,L]
{% endfor %}

이렇게하면 사이트를 빌드 할 때마다 .htaccess가 동적으로 생성되며 include구성 파일에서 .htaccess가 _site디렉터리 로 만들도록합니다 .

RewriteRule ^blog/my/old/path.php /my-new-path/ [R=301,L]

거기에서 _siteApache를 사용하여 제공하는 것은 귀하에게 달려 있습니다 . 일반적으로 전체 Jekyll 리포지토리를 웹 루트가 아닌 디렉토리에 복제하면 내 가상 호스트가 _site폴더에 대한 심볼릭 링크입니다 .

ln -s /path/to/my-blog/_site /var/www/vhosts/my-blog.com

타다! 이제 Apache는 원하는 HTTP 응답 코드를 사용하는 .htaccess 기반 리디렉션을 통해 가상 루트에서 _site 폴더를 제공 할 수 있습니다!

redirecthtaccess 루프에서 사용할 리디렉션 코드를 지정하기 위해 각 게시물의 머리말에있는 속성을 사용하여 매우 멋지게 만들 수도 있습니다.


플러그인에서 리디렉션

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

GitHub에서 지원하며 쉽게 사용할 수 있습니다.

_config.yml

gems:
  - jekyll-redirect-from

a.md

---
permalink: /a
redirect_to: 'http://example.com'
---

https://help.github.com/articles/redirects-on-github-pages/에 설명 된대로

지금:

firefox localhost:4000/a

로 리디렉션됩니다 example.com.

플러그인은 redirect_to페이지에 의해 정의 될 때마다 인계 됩니다.

GitHub 페이지 v64에서 테스트되었습니다.

Note: this version has a serious recently fixed bug which wrongly reuses the default layout for the redirect: https://github.com/jekyll/jekyll-redirect-from/pull/106

Manual layout method

If you don't feel like using https://github.com/jekyll/jekyll-redirect-from it's easy to implement it yourself:

a.md

---
layout: 'redirect'
permalink: /a
redir_to: 'http://example.com'
sitemap: false
---

_layouts/redirect.html based on Redirect from an HTML page :

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Redirecting...</title>
  {% comment %}
    Don't use 'redirect_to' to avoid conflict
    with the page redirection plugin: if that is defined
    it takes over.
  {% endcomment %}
  <link rel="canonical" href="{{ page.redir_to }}"/>
  <meta http-equiv="refresh" content="0;url={{ page.redir_to }}" />
</head>
<body>
  <h1>Redirecting...</h1>
  <a href="{{ page.redir_to }}">Click here if you are not redirected.<a>
  <script>location='{{ page.redir_to }}'</script>
</body>
</html>

Like this example, the redirect-from plugin does not generate 301s, only meta + JavaScript redirects.

We can verify what is going on with:

curl localhost:4000/a

The best option is to avoid url changes altogether by setting the permalink format in _config.yml to match your old blog.

Beyond that, the most complete solution is generating redirect pages, but isn't necessarily worth the effort. I ended up simply making my 404 page a bit friendlier, with javascript to guess the correct new url. It doesn't do anything for search, but actual users can get to the page they were looking for and there's no legacy stuff to support in the rest of the code.

http://tqcblog.com/2012/11/14/custom-404-page-for-a-github-pages-jekyll-blog/


Since github doesn't allow 301 redirects (which isn't surprising), you'll have to make a decision between moving to your new URL structure (and taking a search engine hit) or leaving the URLs the way they are. I suggest you go ahead and make the move. Let the search engine chips fall where they may. If someone hits one of your old links via the search engine, they'll be redirected to the new location. Over time, the search engines will pick up your changes.

Something you can do to help matters is to create a Sitemap where you only list your new pages and not the old ones. This should speed up the replacement of old URLs with the new ones. Additionally, if all your old URLs are in your '/programovani' directory, you can also use a robots.txt file to tell future crawls they should ignore that directory. For example:

User-agent: *
Disallow: /programovani/

It will take a little while for the search engines to catch up with the changes. This isn't really a big deal. As long as the old URLs still exist and redirect actual people to the active pages, you'll be fine.


As others have mentioned, the best solution is to preserve working URLs or duplicate the pages and specify a canonical URL.

Since github pages doesn't support true redirects, I chose to set up rerouter on Heroku to return 301 (permanent) redirects from my site's old domain to the new one. I described the details here:

http://joey.aghion.com/simple-301-redirects/


Jekyll has gone through some major updates in the past few months, so maybe this wasn't possible when this question was originally posted...

Jekyll supports a permalink attribute in the YAML front-matter section of your blog posts. You can specify the URL that you would like your post to have and Jekyll will use that (instead of the filename) when generating your site.

---
title: My special blog post
permalink: /programovani/2010/04/git-co-to-je-a-co-s-tim
---
My blog post markdown content

참고URL : https://stackoverflow.com/questions/10178304/what-is-the-best-approach-for-redirection-of-old-pages-in-jekyll-and-github-page

반응형