Hugo aliases에서 noindex로 인한 SEO 문제 해결하기

Hugo에서 aliases를 사용하면 해당 주소는 meta tag를 이용한 redirect를 페이지가 생성됩니다. 이러한 형태는 일반적으로 url을 이동하기엔 적합하지만, 30x의 status code가 아니고 200이기 때문에 구글 등 검색 봇이 해당 페이지를 수집하게 됩니다.

그래서 Hugo는 이를 방지하기 위해 meta 태그 내 noindex를 사용하여 검색 수집을 제한하고 있습니다.

The http-equiv=”refresh” line is what performs the redirect, in 0 seconds in this case. If an end user of your website goes to https://example.com/posts/my-old-url, they will now be automatically redirected to the newer, correct URL. The addition of meta name=”robots” content=”noindex” lets search engine bots know that they should not crawl and index your new alias page.

다만 jekyll to hugo, 또는 여러가지 이유로 기존에 수집된 링크를 alias로 사용하는 경우 아래 이미지와 같이 google search console(다른 SEO도구도 비슷하죠)에서 noindex 관련 색인 에러가 발생합니다.

물론 이는 지극히 정상적이지만, 이로 인해서 기존의 수집된 색인을 잃거나 SEO 점수 자체에 영향을 줄 수 있습니다. (저는 영향을 좀 많이 받은 케이스에요)

Hugo의 코드는 override가 가능하기 때문에 layouts/alias.html 경로에 코드를 새로 작성하여 이를 예방할 수 있습니다. 이 때 해당 페이지는 redirect 페이지라서 다수가 이런 형태로 존재하면 SEO 점수에 직접적인 영향을 끼칠 수 있습니다. canonical 속성을 이용하여 대표 주소를 본래 주소로 덮는 형태로 코드를 만들면 크게 변화 없이 NOINDEX 색인 에러를 줄일 수 있습니다.

<!DOCTYPE html>
<html>
  <head>
    <title>{{ .Permalink }}</title>
    <link rel="canonical" href="{{ .Permalink }}"/>
    <meta charset="utf-8" />
    <meta http-equiv="refresh" content="0; url={{ .Permalink }}" />
  </head>
</html>

layouts/alias.html

이제 build 후 페이지 내용을 확인해보면 canonical로 표기 및 redirect 처리됩니다.

http localhost:1313/p/ssrf-open-redirect-cheat-sheet.html
HTTP/1.1 200 OK
Accept-Ranges: bytes
Content-Length: 306
Content-Type: text/html; charset=utf-8

<!DOCTYPE html>
<html>
<head>
  <title>http://localhost:1313/phoenix/ssrf-open-redirect/</title>
  <link rel="canonical" href="http://localhost:1313/phoenix/ssrf-open-redirect/"/>
  <meta charset="utf-8" />
  <meta http-equiv="refresh" content="0; url=http://localhost:1313/phoenix/ssrf-open-redirect/">
</head>
</html>

참고로 noindex를 통한 검색 제한과 canonical을 통한 검색 제한은 아래의 특성이 있습니다. 솔직히 제가 이쪽으론 잘 아는게 아니다보니 어떤게 더 좋은 방향인지는 잘 모르겠지만 일반적으로 사용되는 장단점이 있으니 참고하시길 바래요!

  내용
noindex - 검색하는 사용자에게 도움이 되지 않는 페이지를 숨길 때 유용합니다.
- 수집은 하지만 검색 결과에 노출하고 싶지 않을 때 사용합니다.
canonical - 중복된 컨텐츠를 처리할 때 유용합니다.
- 그대로 리포스팅되는 경우에서 검색 우위 및 원본을 표기하기 유리합니다.
(왜냐면 canonical 값으로 이게 원본이라는 표기가 본문에 들어가기 때문에)

byebye noindex!