やりたかったのは、
.htaccess に Redirectmatch ディレクティブを書いて 404 を削減、みたいなこと。
こんな感じにしたい。
- 旧: http://himajin-senyo.com/diary/20090206.html
- 新: http://himajin-senyo.com/2009/02/06/
利用しているサーバは Apache 1.3系 らしいので、マニュアルを確認しよう!
RedirectMatch (.*)\.gif$ http://www.anotherserver.com$1.jpg
OK、正規表現が使えるのは知ってた。Redirectmatchだし。
でも、どんな正規表現を利用できるのか知らんかった。
マニュアルを確認しよう!
Definitions of terms used to describe Apache directives
- regex
- A regular expression, which is a way of describing a pattern to match in text. The directive definition will specify what the regex is matching against.
…。
Apache Server Frequently Asked Questions
What are "regular expressions"?
Regular expressions are a way of describing a pattern - for example, "all the words that begin with the letter A" or "every 10-digit phone number" or even "Every sentence with two commas in it, and no capital letter Q". Regular expressions (aka "regex"s) are useful in Apache because they let you apply certain attributes against collections of files or resources in very flexible ways - for example, all .gif and .jpg files under any "images" directory could be written as /\/images\/.*(jpg|gif)$/.
The best overview around is probably the one which comes with Perl. We implement a simple subset of Perl's regex support, but it's still a good way to learn what they mean. You can start by going to the CPAN page on regular expressions, and branching out from there.
OK、Perl と一緒であることはわかった。王道だよね。
perlre - Perl regular expressions
DESCRIPTION
This page describes the syntax of regular expressions in Perl.
OK、完璧に理解した!嘘ですごめんなさい。
結論。
RedirectMatch /diary/(....)(..)(..)\.html$ http://himajin-senyo.com/$1/$2/$3/
以上。