
環境
centos5.4
apache 2.2
httpd.confファイルの設定 モジュールの読み込み
vi /etc/http/conf/httpd.conf #LoadModule rewrite_module modules/mod_rewrite.so ↓ コメントを外す LoadModule rewrite_module modules/mod_rewrite.so /etc/init.d/httpd restart
RewriteRule記述
記述場所:httpd.conf、.htaccess
記述内容例
<IfModule mod_rewrite.c>
# エンジンを起動(必須)
RewriteEngine On
# http://***/index.phpでアクセスされたら、404にリダイレクト
RewriteRule ^/index.php$ - [R=404,L]
# http://***/testでアクセスされたら、http://***/index.htmlにリダイレクト
RewriteRule ^/test$ ^/index.html [R,L]
# 条件分です。RewriteCondは条件を記述できます。
# 複数設定可能。
# 基本and条件。[OR]をつけることでOR条件も可能
# 以下はIPが127.0.0.1以外のIPでhttp://***/testにアクセスした場合、404へリダイレクト
RewriteCond %{REMOTE_ADDR} !^127.0.0.1$
RewriteRule ^/test$ - [R=404,L]
</IfModule>
httpd.confに記述する場合、apacheの再起動もしくはgracefulが必要