Need some help with a little php code

Discussion in 'PHP' started by pavelbarchuk, Jun 20, 2009.

  1. #1
    my website is build from php so my url's are something like, /php?id=17. Anyways, i want to make the url like /something-something-cool and i want the /php?id=17 page appear on the mew link.

    What is the code, or how do you call out php functions to open in different urls? im doing this for better SEO, so i could add custom meta tags for every page. Any suggestions?
     
    pavelbarchuk, Jun 20, 2009 IP
  2. krishmk

    krishmk Well-Known Member

    Messages:
    1,376
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    185
    #2
    krishmk, Jun 20, 2009 IP
  3. pavelbarchuk

    pavelbarchuk Peon

    Messages:
    163
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks, really nice tool, but, it only changes the url. I need to change the page a bit so i could stick meta tags to it and rename some pages...
     
    pavelbarchuk, Jun 20, 2009 IP
  4. stOK

    stOK Active Member

    Messages:
    114
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    53
    #4
    General Idea for this is:
    using mod_rewrite redirect all *.html URLs to one script say index.php.
    Inside index.php you analize the page name user requested and decide what id should service the responce. Then you include your /php passing it appropriate id.
     
    stOK, Jun 20, 2009 IP
  5. ezprint2008

    ezprint2008 Well-Known Member

    Messages:
    611
    Likes Received:
    15
    Best Answers:
    2
    Trophy Points:
    140
    Digital Goods:
    1
    #5
    ezprint2008, Jun 20, 2009 IP
  6. livedating

    livedating Active Member

    Messages:
    161
    Likes Received:
    0
    Best Answers:
    1
    Trophy Points:
    83
    #6
    I came for the same problem with my website www.dom2000.com.ua.

    I have created an array of all keywords of articles like and then mapped it to IDs:
    
    $map = array(
    'my_page' => 1,
    'other_page' => 2,
    'super_page' => 3,
    );
    $rmap = array_flip($map);
    $prefix = 'x_';
    
    Code (markup):
    All they are started with specific prefix. Then the routers (or any initial script) parses the $_SERVER['REQUEST_URI'], checks if it starts with that prefix and if yes, extracts the ID from mapping array.

    
    function get_id() {
      $id = @$_GET['id'];
      if (strpos($_SERVER['REQUEST_URI'], $prefix)!==false) {
        $s = substr($_SERVER['REQUEST_URI'], strlen($prefix));
        if (isset($map[$s]) {$id = $map[$s]; break; };
      }
      return $id;
    }
    
    Code (markup):
    When you create links, you search array for ID and get the keywords part of it:
    
    function url_by_id($id) {
      $url = '/?id='.$id;
      if (isset($rmap[$id])) $url = $prefix.$rmap[$id];
      return $url;
    }
    
    Code (markup):
    Here are a few examples (in Ukrainian), $prefix='kiev_':

    Купить склад в Киеве Продать склад в Киеве Арендовать склад в Киеве Сдать склад в Киеве

    Купить дом/коттедж в Обуховском районе Купить дом/коттедж в Бориспольском районе Купить дом/коттедж в Киево-Святошинском районе Купить дом/коттедж в Васильковском районе
     
    livedating, Jun 23, 2009 IP