You cannot do this in .htaccess unless you pre-define (hard code) all names in advance (well, you can use RewruteMap but that is close to hard-coding). The reason is -- how can you identify what is song_name and what is album_name if they both have the same syntax? Also .. sometimes you have situations when album name is a song name at the same time (album named after the song) -- how can you identify which one is which?
You have few options here:
1) Redirect everything to your controller.php
and implement routing logic inside (using PHP only). There you can query database and see what the actual parameter is -- album or song.
2) Implement 3-tier URL structure (this will allow RewriteRules to properly identify what is what):
/singer-name
for singers
/singer-name/album-name
for albums
/singer-name/album-name/song-name
for songs
3) Add some additional info/code into URL so mod_rewrite can see the difference between album-name & song_name. For example:
/singer-name
for singers
/singer-name/album-name_a
for albums (_a
will tell that this is the album)
/singer-name/song-name_s
for songs (_s
will tell that this is the song)
or
/singer-name/s_song-name
for songs
or add no such code for songs, as albums URLs will have such code already.
I personally prefer #2 -- it has more logical hierarchy.
UPDATE: These are the rules for scenario #2. You can use these characters: any latin letter (upper and lower case), digits, underscore _
and minus -
. This will cover the following URLs:
/britney-spears
-- singer url
/britney-spears/Femme-Fatale
-- album url
/britney-spears/Femme-Fatale/Till-the-World-Ends
-- song url
RewriteEngine On
# Do not do anything for already existing files
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .+ - [L]
# work with artist URLs
RewriteRule ^([a-z0-9\-_]+)$ /core/controller.php?singer=$1 [NS,QSA,L]
# work with album URLs
RewriteRule ^([a-z0-9\-_]+)/([a-z0-9\-_]+)$ /core/controller.php?singer=$1&album=$2 [NS,QSA,L]
# work with songs URLs
RewriteRule ^([a-z0-9\-_]+)/([a-z0-9\-_]+)/([a-z0-9\-_]+)$ /core/controller.php?singer=$1&album=$2&song=$3 [NS,QSA,L]
It's up to you if you going to use all lower case letters or mixed-case. I would recommend all lower case for consistency.