Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm creating SEO friendly urls for my news page.

My links look like this :

www.site.com/1234/the-pretty-url-string/

RewriteRule ^([^/])/([^/])/$ /news.php?sid=$1&url=$2 [L]

This works great, but I like to have more flexability.

I want to be able to accept urls like :

www.site.com/1234

www.site.com/1234/

so then I can do some php $GET's and figure out if anything is missing - and 301 to the proper URL of my choice. I would like the &url=$2 to be optional.

share|improve this question

1 Answer 1

This works for me:

RewriteRule ^/([^/]+)(?:/([^/]+))?/?$ /news.php?sid=$1&url=$2 [L]
share|improve this answer
    
hmm .. no luck with that. I test different url's and nothing parsed. –  Brian S. Jan 11 '11 at 20:43
    
I edited my original answer after testing it :). Let me know if that works for you. –  bgould Jan 11 '11 at 21:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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