7
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Basic認証を掛けた状態でSNSシェアをデバッグする

Last updated at Posted at 2018-11-26

2022.06.24

Apache2.4系の書き方に変更
ヘルスチェック時の許可を追記

本題

Basic認証掛かってると
TwitterのCardValidatorとかFacebookのシェアデバッガのクローラがサイトに入れないので
特定のUAを持ってるやつは通過を許可してあげる。
.htaccessに以下を追記する。


SetEnvIf User-Agent "^facebookexternalhit.*$" crawler_fb
SetEnvIf User-Agent "^facebookplatform.*$" crawler_fb2
SetEnvIf User-Agent "^Twitterbot.*$" crawler_tw

AuthType Basic
AuthGroupfile /dev/null
AuthName "Please enter your ID and password"
AuthUserfile /home/tapioka/.htpasswd
#require valid-user ここはコメントアウト

# ヘルスチェック用ファイルは許可(ロードバランサがアクセス出来るように)
SetEnvIf Request_URI "^/health.html" health

# 以下のいずれかに該当する場合のみアクセスを許可
<RequireAny>
    Require valid-user
    Require env health
    Require env crawler_fb
    Require env crawler_fb2
    Require env crawler_tw
</RequireAny>

確かLINEもfacebookexternalhitのUAを持ってたので
FB,TW,LIと対応したのが上記設定。

7
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
11

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?