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