SEO Friendly URL Rewrites

I've seen lots of other questions and demos out there, but I'm still a little fuzzy on this business of search engine friendly URLs.

If I have a url like this:  http://www.foobar.com/services.php?id=1

How can I make this search engine friendly, without messing up the dynamic variables passed to my website, which determines content?

Also, is there a generic set of .htaccess rules that would work for this?  I have several sites that use this simple structure of www.SITE.com/sectionname.php?page=id

And I've seen some sites that look more like this: www.SITE.com/sectionname/pagename (no .php)
LVL 12
rowejdAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wassa_rCommented:
If you don't want to mess up the dynamic variables that popuplate the content, you'll have to pass the id in the new URL as well.

So, you could rewrite it from /services.php?id=1 to
/services/name-1.

A general rule for rewriting something like pageName.php?id=1 to pagename/asdf-1 could look like this:
RewriteRule ^([^\/]+)\/.+\-([0-9]+)$ /$1.php?id=$2 [L]

It takes the part before the / as the sectionname ( .php ), the second part is the pagename and page id.

so /asdf/sadfas-1 would go to asdf.php?id=1.

Hope this helps.
0
rowejdAuthor Commented:
This doesn't seem to be working.

RewriteEngine on
RewriteRule ^([^\/]+)\/.+\-([0-9]+)$ /$1.php?id=$2 [L]

Doesn't change my url:
http://www.mysite.com/section/pagename.php?id=8
0
wassa_rCommented:
No, it changes an url like /section/pagename-8 to /pagename/doesntmatter-8 to /pagename.php?id=8. It does not take extra folder depths in account. If you wan't to do things as extensive as that you might wan't to consider doing it in PHP itself.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.