将虚荣URL链接到查询字符串URL

I'm trying to link non-existent vanity URLs such as:

www.sample.com/albums/artist/title

... to resources that take the form of:

www.sample.com/albums/album.php?id=1

I know this requires some Apache redirect or internal rewrite, but no example I've found seems to work for me. It either: does nothing; or gives an error.

How to you propose Apache knows which album has which ID..?

In short, you cannot link an album name to an ID like that. The information has to come from somewhere. What you can do, however, is to add support for looking up via the name of the album. Then you can use a redirect to something like this:

www.sample.com/albums/album.php?artist=\1&name=\2


Edit, added:

Seeing there is a set and unchanging number of albums, this question becomes a very simple one. What you have is a number of static URLs, which should be mapped to another static URL. Which is the first example listed in the Apache Rewrite Engine manual.

So simply map /albums/artist_1/title_1 to albums/albums.php?id=1, and do this for each album you have.

Not very elegant, but it is the simplest and least error-prone solution.