Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6218777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T07:40:03+00:00 2026-05-24T07:40:03+00:00

I am running PHP5.3.6 and IIS7. I am currently working on a product centric

  • 0

I am running PHP5.3.6 and IIS7. I am currently working on a product centric site where I have one php page that dynamically generates a page based on a query string such as /product.php?id=12345.

The volume of products that I have in the database varies, but measures in the hundreds. They have unique IDs and names.

I want for each page to be addresses by their name instead of by the query string.

For example, instead of:

/product.php?id=12345

I would prefer:

/acme-super-widget-in-blue-with-cool-groovy-gadget-attachment

I have the URL Rewrite component in IIS7, but I don’t want to enter values manually. I would rather have a dynamic process in place. I believe the needed functionailty here is to add an URL Rewrite rule to the web.config file, but I’m not sure if that is true or the best approach.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T07:40:04+00:00Added an answer on May 24, 2026 at 7:40 am

    I would recommend using the ID along with the name so that you can support products with the same name (future proofing), or products with non-ascii characters… should you have international names. I would also recommend using only ascii characters in the URL’s for now as I’ve noticed some sites and browser tend to expand non-ascii characters in to ugly percent encoding.

    IIS 7 is a bit trickier than Apache, but I think this might work for you http://blogs.iis.net/bills/archive/2008/05/31/urlrewrite-module-for-iis7.aspx

    Here is an example rewrite rule which will strip the name off the id and pass just the id to the script.

    IIS 7 Using the module in the link above

    Match URL

    ^([0-9]+)[^/]*/?$
    

    Action

    index.php?id={R:1} [QSA,L]
    

    Apache just for good messure 😉

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([0-9]+)[^/]*/?$ index.php?id=$1 [QSA,L]
    

    Here is a PHP function that will generate the id name portion of your friendly URLs.

    function friendlyURL($id, $title) {
    
        $string = $title;
        $paramcount = func_num_args();
        for ($i = 2; $i < $paramcount; $i++) {
            $string .= "-" . func_get_arg($i);
        }
        $string = preg_replace('`&(amp;)?#?[a-z0-9]+;`i', '-', $string);
        $string = htmlentities($string, ENT_COMPAT, "utf-8");
        $string = preg_replace("`&([a-z]+);`i", "", $string);
        $string = preg_replace("`['\[\]]`", "", $string);
    
        $tmp = $string;
        $string = preg_replace(array("/[^A-Za-z0-9]/", "`[-]+`"), "-", $string);
    
        $string = trim($string, '-');
        return trim($id . "-" . $string, '-');
    }
    

    This would give you URL’s like

    Product ID = 12345, Name = “acme super widget”

    /12345-acme-super-widget/
    

    Product ID = 12345, Name = “Japanese product ギター”

    /12345-japanese-product/
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an old osCommerce site that was PHP4, now running on PHP5. Named
Having a really strange problem. Scenario: PHP5.2.9, IIS7, PHP running as FastCGI. I have
I have a web server that is running PHP 5.3.6 non thread safe (VC9),
I have Joomla 1.5.9 running with php 5.2.8, mySQL 5.1.31 on IIS7 on a
I have been developing our php based site on a development box that was
I've got a web server running IIS7 and I just updated to PHP 5.3.
I have a PostgreSQL, php5, running on Apache2.0 (on a Windows machine.) I want
I have PHP 5.1.6 running with a ton of mods and extensions enabled, is
I'm running ubuntu 10.04 and have installed php5 via the following: sudo aptitude install
I'm running PHP5 and Apache with mod_rewrite enabled. As we know on every page

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.