facebook twitter hatena line email

Htaccessメモ

提供: 初心者エンジニアの簡易メモ
2018年4月6日 (金) 14:24時点におけるAdmin (トーク | 投稿記録)による版 (特定UserAgent と IPアドレスを許可するように)

移動: 案内検索

.htaccessを使う

httpd.confのAllowOverrideをallに変更

AllowOverride None
↓
AllowOverride all

あるドメインのみ弾く403

Order allow,deny
Allow from all
Deny from localhost

だめなら<Files>で囲む

<Files *>
 Order allow,deny
 Allow from all
 Deny from localhost
</Files>

あるIPのみ許可

order deny,allow
deny from all
allow from 192.168.11.2
allow from 127.0.0.1
allow from 192.168.196.0/24

特定UserAgent と IPアドレスを許可するように

Order deny,allow
Deny from all
SetEnvIf User-Agent "iPhone" allowsystem
SetEnvIf User-Agent "iPod" allowsystem
SetEnvIf User-Agent "ELB-HealthChecker" allowsystem
Allow from env=allowsystem
Allow from 127.0.0.1

404のとき専用404ページを飛ばす

ErrorDocument 404 http://localhost/404.html

basic認証

<Directory "/var/www/html">
    Satisfy Any
    AuthType Basic
    AuthName "Please enter your ID and password"
    AuthUserFile /home/user1/.htpasswd
    Require valid-user
    Order deny,allow
    deny from all
</Directory>

.htaccessでmod_rewriteを使う

Options FollowSymLinks Includes
RewriteEngine on
RewriteRule a.jpg$ http://localhost/ [R=301,L]

htpasswd作成

htpasswd -cb .htpasswd1 user1 pass1