SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Mod Rewrite Rule for change in URL structure

    I am in need of a mod rewrite rule to correctly change an existing url structure that looks like this:

    Old:
    somesite.com/scripts/data/database.cgi?ArticleID=29154&report=SingleArticle&file=Data

    Into something that looks like this:

    New:
    somesite.com/oldarticle/id29154.htm

    What I came up with isn't working, but I know I'm close:

    RewriteRule ^scripts/data/database\.cgi?ArticleID=([0-9]+)&report=SingleArticle&file=Data$ ^oldarticle/id$1\.htm [R=301,NC,L] # Permanent Move

    Any help would be greatly appreciated!

    Thanks,

    Dennis
    Last edited by Mittineague; Oct 1, 2013 at 21:13. Reason: delinking example URLs
    Free Invisible Counter - Unlimited Stats - Track AdSense!!!
    PHPTextAd - Text Ad Management Script

  2. #2
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,604
    Mentioned
    19 Post(s)
    Tagged
    2 Thread(s)
    Hi Dennis,

    That resembles the "Loopy Code" I discuss in my signature's tutorial. I recommend a read of that but, in summary, You also are unaware that query strings can only be examined (in mod_rewrite) by RewriteCond statements (the tutorial notes that very quickly).

    Basically, what you want is to redirect from a usable link to an unusable (human format) link and then ask Apache to devine what you want it to serve.

    Instead,

    1. Test whether the {REQUEST_URI} is the original request (best to check the code in the tutorial).

    2. Capture the query string (in whole or parts) then redirect to new format.

    3. Redirect new format to the "servable" format.

    The first item is critical as it will prevent code looping.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •