読者です 読者をやめる 読者になる 読者になる

purazumakoiの[はてなブログ]

技術メモから最近はライフログも増えてきてます。

特定の国コードからきたらリダイレクトする

スパム対策の為

  • IE6から
  • 日本以外

だったらindex2.htmlを表示するようにした。

アクセスしたURLが

http://exsample.com/index.html とか http://exsample.com/index.phpなら

の辺りで指定可能だったが
http://exsample.com
のようにルートを指定する時に適用させる事ができなくてこまった。


結果こうした

RewriteEngine on

# スパム対策でIE6はindex2.htmlに
RewriteCond %{HTTP_USER_AGENT} "MSIE 6\.0"
RewriteRule ^$ index2.html [L]

# IE6以外はindex.phpを実行となる
RewriteCond %{HTTP_USER_AGENT} !"MSIE.6\.0"
RewriteRule ^$ index.php [L]


# 国コード対策

#ここまで来ているのはindex.phpを実行しているので↓が適用される
<Files ~ "^index\.php$">
order allow,deny
allow from all
deny from .ad
deny from .ae
deny from .ag
deny from .ai
deny from .al
deny from .am
deny from .an
deny from .ao
deny from .aq
deny from .ar
deny from .at
deny from .au
deny from .aw
deny from .az
deny from .ba
deny from .bb
deny from .be
deny from .bf
deny from .bg
deny from .bh
deny from .bi
deny from .bj
deny from .bm
deny from .bn
deny from .bo
deny from .br
deny from .bs
deny from .bw
deny from .by
deny from .bz
deny from .ca
deny from .cf
deny from .cg
deny from .ch
deny from .ci
deny from .ck
deny from .cl
deny from .cm
deny from .cn
deny from .co
deny from .cr
deny from .cu
deny from .cv
deny from .cy
deny from .cz
deny from .de
deny from .dj
deny from .dk
deny from .dm
deny from .do
deny from .dz
deny from .ec
deny from .ee
deny from .eg
deny from .er
deny from .es
deny from .et
deny from .fi
deny from .fj
deny from .fm
deny from .fo
deny from .fr
deny from .gb
deny from .gd
deny from .ge
deny from .gf
deny from .gg
deny from .gh
deny from .gi
deny from .gl
deny from .gn
deny from .gp
deny from .gr
deny from .gt
deny from .gu
deny from .gy
deny from .hk
deny from .hn
deny from .hr
deny from .hu
deny from .id
deny from .ie
deny from .il
deny from .im
deny from .in
deny from .ir
deny from .is
deny from .it
deny from .je
deny from .jm
deny from .jo
deny from .ke
deny from .kh
deny from .ki
deny from .kn
deny from .kr
deny from .kw
deny from .ky
deny from .kz
deny from .la
deny from .lb
deny from .lc
deny from .li
deny from .lk
deny from .ls
deny from .lt
deny from .lu
deny from .lv
deny from .ma
deny from .mc
deny from .md
deny from .mg
deny from .mh
deny from .mk
deny from .ml
deny from .mn
deny from .mo
deny from .mp
deny from .mr
deny from .mt
deny from .mu
deny from .mv
deny from .mw
deny from .mx
deny from .my
deny from .mz
deny from .na
deny from .nc
deny from .ne
deny from .nf
deny from .ng
deny from .ni
deny from .nl
deny from .no
deny from .np
deny from .nz
deny from .om
deny from .pa
deny from .pe
deny from .pf
deny from .pg
deny from .ph
deny from .pk
deny from .pl
deny from .pr
deny from .pt
deny from .py
deny from .qa
deny from .ro
deny from .ru
deny from .rw
deny from .sa
deny from .sb
deny from .se
deny from .sg
deny from .si
deny from .sk
deny from .sm
deny from .sn
deny from .sr
deny from .su
deny from .sv
deny from .sy
deny from .sz
deny from .tg
deny from .th
deny from .tn
deny from .to
deny from .tr
deny from .tt
deny from .tv
deny from .tw
deny from .tz
deny from .ua
deny from .ug
deny from .uk
deny from .us
deny from .uy
deny from .uz
deny from .va
deny from .vc
deny from .ve
deny from .vi
deny from .vn
deny from .vu
deny from .ws
deny from .ye
deny from .yu
deny from .za
deny from .zm
deny from .zr
deny from .zw

# 日本は制限しないのでコメントアウト
#deny from .jp

ErrorDocument 403  http://exsample.com/index2.html
</Files>

こんな感じで意図した通りに動いた。
がキャッシュ云々で本当にOKか不安だなぁ