SEO Friendly URL Rewrites

Posted on 2008-11-18
Medium Priority
Last Modified: 2013-12-09
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)
Question by:rowejd
  • 2

Expert Comment

ID: 22989601
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

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.
LVL 12

Author Comment

ID: 22997902
This doesn't seem to be working.

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

Doesn't change my url:

Accepted Solution

wassa_r earned 2000 total points
ID: 23002282
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.

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Australian government abolished Visa 457 earlier this April and this article describes how this decision might affect Australian IT scene and IT experts.
Strategic internal linking is often considered an SEO power technique, especially for content marketing. Do you need to hire an SEO agency to optimize you internal linking? No, this article will help you understand the basics of internal linking and…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month17 days, 5 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question