Can't this easily be constructed by appending a `'/'` and the `title` from the question? In PHP: $question_url .= '/' . preg_replace('/[^\w_]/','',str_replace(' ','_'$question->title));