Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Possible Duplicate:
I need a little help with .htaccess rewrite

Hello, I need a little help with .htaccess file. I have songs, singers and albums links I want to rewrite.

I already rewrote the links and they are like this:

  • for the songs is like this: /song/song_name
  • for singers: /singer_name
  • for albums: /album_name

This is the code in my .htaccess file:

RewriteEngine on
RewriteRule ^singer/([^/\.]+)/?$ /core/controller.php?singer=$1 [L]
RewriteRule ^song/([^/\.]+)/?$ /core/controller.php?song=$1 [L]
RewriteRule ^album/([^/\.]+)/?$ /core/controller.php?album=$1 [L]

I need the links for the songs, singers and albums to be like this:

  • for songs /singer_name/song_name
  • for singers /singer_name
  • for albums /singer_name/album_name

Can anyone help me with this please.

share|improve this question

migrated from stackoverflow.com Jun 20 '11 at 0:30

This question came from our site for professional and enthusiast programmers.

marked as duplicate by John Conde Jun 20 '11 at 13:16

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

i will try in their thanks – Pinokyo Jun 19 '11 at 10:22
up vote 3 down vote accepted

for /singer_name add:

RewriteCond $1 !^(singer|song|album)
RewriteRule ^/?([^/\.]+)/?$ /core/controller.php?singer=$1 [L]

for /singer_name/song_name add:

RewriteCond $1 !^(singer|song|album)
RewriteCond $3 !^(album)
RewriteRule ^/?([^/\.]+)(/([^/\.]+))?.*$ /core/controller.php?singer=$1&song=$3 [L]

for /singer_name/album/album_name add:

RewriteCond $1 !^(singer|song|album)
RewriteCond $3 (album)
RewriteRule ^/?([^/\.]+)(/([^/\.]+))?.*$ /core/controller.php?singer=$1&album=$3 [L]


Sorry, but rewriting: /singer_name/song_name and /singer_name/album_name can not be done at the same time, as Apache doesn't know the difference between Song name and Album name, unless all song name start with numbers like: 01. Song Name etc.

share|improve this answer
yeah i figured this out at the first time i tried this, i went back to previuos solution for songs /song/song_name singer: /singer/singer_name albums /album/album_name. – Pinokyo Jun 19 '11 at 12:13

Not the answer you're looking for? Browse other questions tagged or ask your own question.