Results 1 to 4 of 4
  1. #1
    Join Date
    Jan 2004
    Location
    Denmark
    Posts
    21

    Smart rewrite of URL - can it be done?

    I have the following URL which i'd like to rewrite (mod_rewrite). Im a bit unsure in regards of this can be done, so you could say im also looking for answer to that.

    The URLs shows 3 different hints the the title "doom4"

    urls:

    viewtitle.php?platform=ps2&title=doom4&type=hints&id=23405

    viewtitle.php?platform=ps2&title=doom4&type=hints&id=22788

    viewtitle.php?platform=ps2&title=doom4&type=hints&id=13120

    I wish the rewrite these URLs so they don't fill out so much. My problem is that I dont want the long and different id numbers in the rewrite, but rewrite the id numbers, so they are defined in the following way;

    www.domain.com/ps2/doom4/hints-1.html - has number 1 because it's the first(lowest id) hint which is added to the database.- Id "13120"
    www.domain.com/ps2/doom4/hints-2.html - Id "22788"
    www.domain.com/ps2/doom4/hints-3.html - Id "23405"

    I have no problem rewriting the URLs if the long id number are used (but im looking for the first solution), like;

    www.domain.com/ps2/doom4/hints-13120.html
    www.domain.com/ps2/doom4/hints-22788.html
    www.domain.com/ps2/doom4/hints-23405.html

    BUT like I said, im looking for the first solution (if it can be done?)

  2. #2
    Join Date
    Dec 2004
    Location
    New York City, NY, USA
    Posts
    735
    From what you've told us, no.

    You're going to have some kind of mapping from the long id number to the short id; how else would mod_rewrite know? Doing lookups like this in mod_rewrite is painful--you're best using mod_rewrite to rewrite the URL to some other script; that script then does the mapping to the correct URL.

  3. #3

    Arrow

    Nothing stopping you from using mod_rewrite, however you'd need to change the code in viewtopic.php to take advantage of it.

    Example:

    Code:
    RewriteRule ^(\w+)/(\w+)/(\w+)-(\d+).html$ /viewtitle.php?platform=$1&title=$2&type=$3&page=$4 [L]
    PHP Code:
    if (array_key_exists("page"$_GET)) {
      
    // Perform an SQL query here to get the ID for the page number
    } else {
      
    // Use existing code for a search by ID

    blazingfast networks - Xen powered virtual servers from just 10/month

  4. #4
    If the title (doom4) is unique to that set of hints then you could easily do the first option. Just iterate through the results within viewtitle.php until your get to the x one returned. (x being the number 1, 2... etc)

Posting Permissions

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