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.

link|improve this question
feedback

1 Answer

This works for me:

RewriteRule ^/([^/]+)(?:/([^/]+))?/?$ /news.php?sid=$1&url=$2 [L]
link|improve this answer
hmm .. no luck with that. I test different url's and nothing parsed. – Mayhem 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
feedback

Your Answer

 
or
required, but never shown

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