Apache module mod_rewrite
さらに、mod_rewrite ではパターンの前に NOT 文字('!')
が使えます。これで後続のパターンを否定することができます。たとえて
言うならば、``もし現在の URL がこのパターンにマッチ
しなければpattern'' ということです。これは、反対の
パターンを表す方が簡単だったり、最後のデフォルトルールとするなど、
例外的なケースを表現するのにも使えます。
さらに、mod_rewrite ではパターンの前に NOT 文字('!')
が使えます。これで後続のパターンを否定することができます。たとえて
言うならば、``もし現在の URL がこのパターンにマッチ
しなければpattern'' ということです。これは、反対の
パターンを表す方が簡単だったり、最後のデフォルトルールとするなど、
例外的なケースを表現するのにも使えます。
ブログ記事に付けられる番号パラメータのURLを静的URLでアクセスできるようにしたい
- 仕様
http://example.com/post/{記事番号}/ ⇒ http://example.com/post.php?no={記事番号}- サンプルコード
RewriteRule ^post/(.*)/$ /post.php?no=$1 [L]ブログやCMSなど、記事を投稿するごとに番号が振られるシステムを利用している場合の、記事ページに自動的に付加されるパラメータを擬似静的化します。見た目は静的なURLですが、裏ではpost.phpというプログラムにパラメータを渡して処理しています。
- 擬似静的化されたURL
/area/kanto-13-minato/- サンプルコード
RewriteRule ^area/(.*)-(.*)-(.*)/$ /area.php?area1=$1&area2=$2&area3=$3&sort=2 [L]
「www」の有無を統一したい
- 仕様
http://example.com/ ⇒ http://www.example.com/
wwwなしでアクセスがあったら、wwwありに301リダイレクトさせる- サンプルコード
RewriteCond %{HTTP_HOST} ^example\.com [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]URLの正規化の記事で説明したとおり、URLはwwwあり、もしくはwwwなしのどちらかに統一する必要があります。もし検索エンジンに両方認識されてしまった場合には上記のように設定します。
再度push
pushing to http://192.168.30.46/hg/ searching for changes 1 changesets found abort: authorization failed [command interrupted]またエラー
# vi .hg/hgrc [web] push_ssl = false allow_push = *誰でもpushできるように設定。
再々度push
pushing to http://192.168.30.46/hg/ searching for changes 1 changesets found adding changesets adding manifests adding file changes added 1 changesets with 1 changes to 1 files [command completed successfully Mon Dec 07 13:31:03 2009]今度は通った。
Apache Log Analyzer 2 Feed¶
ApacheLogAnalyzer2Feed is a really powerful open source PHP 5 class to parse and analyze Apache Web Server log files. Results are converted into a feed to let users subscribe them with a feed reader.
You can define custom filters based on logs data — for instance User-Agent, IP, requested page... — and combine them to select just a limited resultset.
The class can easily be extended with additional filters and custom feed handlers.Quick Start¶
Would you like to be informed each time GoogleBot visits your website?
ApacheLogAnalyzer2Feed is the solution! ApacheLogAnalyzer2Feed will analyze server logs for you returning results in a custom feed.
Simply using the following code fragment you'll be able to track Googlebot directly from your feed reader.
apache2の再起動時に apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName という警告が出る。
(対処方法)
# vi /etc/apache2/apache2.conf
ServerName 127.0.1.1
# /etc/init.d/apache2 restart
また認証が通った全ユーザーに対してアクセスを許可する場合は次のように記述します。
Require valid-user
なお、初めて.htpasswdファイルを作成するときは-cオプションが必要となる。
# htpasswd -c /etc/httpd/.htpasswd secret
New password:
Re-type new password:
Adding password for user secretそして、Apacheの設定ファイル(/etc/httpd/conf/httpd.conf)に以下の設定を追加する。
<Directory "/var/www/html/member">
AuthType Basic
AuthName "Secret Zone"
AuthUserFile /etc/httpd/.htpasswd
Require user secret
</Directory>