.htaccessとは?
.htaccessファイルの作り方
コメント行は?
.htaccessファイルの設置
.htaccessファイルのパーミッション
設置したら「500 Internal Server Error」が発生?!
.htaccessファイルの設定例
1)ディレクトリでアクセスがあった時のデフォルトファイルを変更する
DirectoryIndex main.html index.html index.htm index.cgi index.shtml index.php |
DirectoryIndex index.php index.html index.htm index.cgi index.shtml |
2)拡張子「html」でも、PHPファイルとして動作するよう設定する
AddHandler application/x-httpd-php .html .php |
AddType application/x-httpd-php .html .php |
3)HTTPレスポンスヘッダの文字コードを設定する
AddDefaultCharset UTF-8 |
AddType "text/html; charset=UTF-8" .html .php |
<?php header("Content-type: text/html; charset=utf-8"); |
4)特定のIPからの接続を拒否する
order allow,deny allow from all deny from XXX.XXX.XXX.XXX |
5)独自のエラー表示
ErrorDocument 401 /error/401.html ErrorDocument 403 /error/403.html ErrorDocument 404 /error/404.html ErrorDocument 500 /error/500.html |
6)アクセス制限の方法
AuthUserFile /home/FTPユーザー名/public_html/フォルダ名/.htpasswd AuthGroupFile /dev/null AuthName "Input your ID and Password." Authtype Basic require valid-user |
user1:usTjXUi1eiWZI user2:usjRS48E8ZADM |
7)リダイレクト
Redirect permanent ディレクトリ名 http://XXX.XXX/ |
8)mod_rewrite
RewriteEngine on RewriteCond %{SERVER_PORT} ^80$ RewriteCond %{HTTP_HOST} ^(ドメイン名)(:80)? RewriteRule ^(.*) http://www.ドメイン名/$1 [R=301,L] |
9)PHPの設定ファイルの値を変更する
php_value mbstring.language Japanese | 言語指定 |
php_value mbstring.internal_encoding UTF-8 | 文字コード指定 |
php_flag short_open_tag on もしくは、 php_flag short_open_tag 1 |
ショートタグ設定 |