mod_rewriteの設定方法

mod_rewriteを使用すれば、アクセスしてきたURLを書き換える事が出来ます。
サイトの移転時等のURL転送等に利用され、最近では動的ページのURLを静的ページのURLに見せかけるといった用途にも使用されています。
mod_rewriteを使いたい場合の設定方法を解説します。
mod_rewrite機能を利用するためには、「apache」の設定ファイル(httpd.conf)を編集します。

「root」アカウントでログインし下記コマンドを入力。

# vi /etc/httpd/conf/httpd.conf

下記の記述を探します。

#LoadModule rewrite_module modules/mod_rewrite.so

#でコメントアウトされていたら#を削除して有効化します。

LoadModule rewrite_module modules/mod_rewrite.so

次にAllowOverRideを設定します。

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
AllowOverride None

上記箇所のAllowOverride NoneをAllowOverride Allに変更します。

AllowOverride All

最後に「Apache」を再起動させます。

# /etc/init.d/httpd restart

これでも反映されない場合は、

AllowOverride None

上記の部分すべてを

AllowOverride All

にして、「Apache」を再起動させます。

# /etc/init.d/httpd restart