#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2013
    Posts
    3
    Rep Power
    0

    How to use mod_rewrite to change URL


    I am not familiar with mod_rewrite at all, as I know I can change URL using htaccess bu can not figure how to do that so I appreciate if anybody can help me with expression that should be placed in htaccess.
    My current URL is
    127.0.0.1/cms/product.php?id=19830&PRODUCT-NAME

    I would like to make it like this
    127.0.0.1/19830-PRODUCT-NAME

    Now i have this rule

    Options +FollowSymlinks
    RewriteEngine on
    RewriteRule ^([^/\.]+)/?$ product.php?id=$1&
    IndexOptions -FancyIndexing

    But server does not return URL in real time, but when I change manually url to desired it returns correct page
    when i type 127.0.0.1/19830-PRODUCT-NAME
    it works when I use link it returns
    127.0.0.1/cms/product.php?id=19830&PRODUCT-NAME

    What am I missing ???

    Thanks
  2. #2
  3. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,128
    Rep Power
    4304
    Welcome to DevShed Forums, grooveszk.

    You need to edit your PHP files to output the user-friendly URLs. mod_rewrite doesn't change the URLs in your pages. It only changes URLs when one that matches one of the rewrite rules is requested by a user.

    Comments on this post

    • grooveszk agrees
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).

IMN logo majestic logo threadwatch logo seochat tools logo