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?
 
wassa_rConnect With a Mentor Commented:
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.