DRYな備忘録

Don't Repeat Yourself.

URLの拡張子を隠したい【debian】【apache】【httpd.conf】【RewriteEngine】

【問題】

新規さくらVPSをDebianのLAMPサーバにする で整えたサーバでウェブページを作成中、ユーザのアクセスするURLから拡張子を消したいと思った。

ユーザが叩くURL

http://hoge.com/fuga

アクセスするファイル

[hoge.comのドキュメントルート]/fuga.html

といった感じ

【失敗】

apache2 on Debian なので、/etc/conf.d/apache2/httpd.conf にて以下のように書き足し

<VertualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot [hoge.comのドキュメントルート]
#ここから書き足し
    RewriteEngine on
    RewriteRule /fuga /fuga.html
#ここまで
</VirtualHost>

として、リスタート

sudo /etc/init.d/apache2 restart

するも...

Syntax error on line 55 of /etc/apache2/httpd.conf:
Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
The Apache error log may have more information.
 failed!

あうっ

f:id:otiai10:20121114224223j:plain

【調査】

/etc/apache2/mods-available

の中を見ると、

rewrite.load

これがあるのに、

/etc/apache2/mods-enabled

の中を見る限り、rewrite.loadが無い。

【解決】

ということで

% cd /etc/apache2/mods-enabled
% ls -la
  # rewrite.load無い
% sudo ln -s ../mods-available/rewrite.load rewrite.load
% ls -la
  # リンク貼られた

で、気を取り直してリスタート

% sudo /etc/init.d/apache2 restart
Restarting web server: apache2 ... waiting .

お、いけたっぽい

http://hoge.com/fuga

にアクセスすると、

URL欄にhttp://hoge.com/fugaと表示されたまま

fuga.htmlの内容が表示された

【参考】

URLを書き換える -Rewrite機能 | Smart -Web Magazine

【備考】

Apacheとか、その辺のレイヤーの勉強するです