1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

URL Rewrite in PHP like wordpress

Discussion in 'PHP' started by ronny10, Jul 14, 2011.

  1. #1
    ronny10, Jul 14, 2011 IP
  2. soniasyril

    soniasyril Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Use htaccess RewriteRule
     
    soniasyril, Jul 14, 2011 IP
  3. ronny10

    ronny10 Well-Known Member

    Messages:
    185
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    108
    #3
    yes i have used htaccess but how i implement

    http://www.website.com/abc.php?vid=55

    TO this url
    website.com/vid/title-of-the-page (here i need slug value title of the page)

    Thanks for reply
     
    ronny10, Jul 15, 2011 IP
  4. ronny10

    ronny10 Well-Known Member

    Messages:
    185
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    108
    #4
    ronny10, Jul 15, 2011 IP
  5. spletnisistemi

    spletnisistemi Peon

    Messages:
    50
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Paste this in file .htaccess:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /blog/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]
    </IfModule>

    # END WordPress
     
    spletnisistemi, Jul 15, 2011 IP
  6. ronny10

    ronny10 Well-Known Member

    Messages:
    185
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    108
    #6
    ronny10, Jul 16, 2011 IP
  7. jazzcho

    jazzcho Peon

    Messages:
    326
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
  8. Kaizoku

    Kaizoku Well-Known Member

    Messages:
    1,261
    Likes Received:
    20
    Best Answers:
    1
    Trophy Points:
    105
    #8
    You need to change your script to accept slug name instead of id.
     
    Kaizoku, Jul 18, 2011 IP
  9. suryawl

    suryawl Peon

    Messages:
    54
    Likes Received:
    3
    Best Answers:
    1
    Trophy Points:
    0
    #9
    basically you need to do two things :
    1. .htaccess to decode the url and send it to abc.php
    2. you need to change the file that create the url. if the page that refer to abc.php?vid=55 is index.php, you need to change your code in index.php

    example :
    old program
    $query = "SELECT id,title FROM vid_table";
    $result = mysql_query($query);

    while ($data = mysql_fetch_array($result))
    {
    echo '<a href="abc.php?vid=' . $data['id'] . '">' . $data['title'] . '</a>';
    }

    new program

    while ($data = mysql_fetch_array($result))
    {
    echo '<a href="abc.php/vid/' . str_replace(" ", "-", $data['title']) . ">' . $data['title'] . '</a>';
    }


    in abc.php you need to change the way the program read to database

    if (isset($_SERVER['REDIRECT_URL'])) /* this is means that the page get redirected from .htaccess */
    {
    $parts = explode('/', $_SERVER['REDIRECT_URL']);

    array_shift($parts);

    $url_name = $parts[1];
    $url_name = str_replace("-", " ", $url_name);
    $query = "SELECT id FROM vid_table WHERE title = '$url_name'";
    $result = mysql_query($query);
    $data = mysql_fetch_array($result);
    $_GET['id'] = $data['id'];
    }

    then you can continue with your program

    i hope it's not too confusing
     
    suryawl, Jul 23, 2011 IP