SEO Friendly URL Rewrites

Posted on 2008-11-18
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:

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

And I've seen some sites that look more like this: (no .php)
Question by:rowejd
    LVL 3

    Expert Comment

    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

    This doesn't seem to be working.

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

    Doesn't change my url:
    LVL 3

    Accepted Solution

    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.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
    It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
    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 a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    761 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

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now