Rewrite id to keyword ?

Discussion in 'PHP' started by ebizaustralia, Feb 6, 2009.

  1. #1
    I have developed a script and its using some id for each post or user,

    eg : site.com/?id=12 etc

    But for SEO and other options I just want to change those ID to keyword or text.

    So what should I do ?

    Can anyone please help ?
     
    ebizaustralia, Feb 6, 2009 IP
  2. lui2603

    lui2603 Peon

    Messages:
    729
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Instead of querying the database by the id, use the post title..
    You could look in to mod_rewrite with .htaccess if you want to make your URL's SEO friendly :)
     
    lui2603, Feb 6, 2009 IP
  3. ebizaustralia

    ebizaustralia Peon

    Messages:
    91
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3

    Good Suggestion.
    But what I need is www.site.com/keyword/

    It it possible ?
     
    ebizaustralia, Feb 7, 2009 IP
  4. Danltn

    Danltn Well-Known Member

    Messages:
    679
    Likes Received:
    36
    Best Answers:
    0
    Trophy Points:
    120
    #4
    Redirect all requests to index.php, then analyse the request url and see which page is requested. You'll need a routing file to keep track of which page applies to which id, then simply show that ID as normal.

    Dan.
     
    Danltn, Feb 7, 2009 IP
  5. steelaz

    steelaz Peon

    Messages:
    47
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #5
    You can add this in your .htaccess file:
    
    RewriteEngine On
    RewriteCond $1 !^(index\.php|assets|sitemap\.xml|robots\.txt)
    RewriteRule ^(.+)$ index.php?$1 [L]
    
    Code (markup):
    It will pass query string to index.php (unless it's calling assets folder or sitemap.xml/robots.txt).

    Then you can use domain.com/var1/var2/ and if you add
    echo $_SERVER['QUERY_STRING'];
    PHP:
    in your index.php it will output "var1/var2"
     
    steelaz, Feb 7, 2009 IP
  6. mdrobiul

    mdrobiul Peon

    Messages:
    186
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Can you discuss in details @steeze ? I also need to do same thing ....
     
    mdrobiul, Feb 7, 2009 IP
  7. darrenbeige

    darrenbeige Peon

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Imagine a MySQL database, with post_id column. You would need to adapt the script so post_id now becomes internet-marketing etc. Then instead of querying MySQL (through PHP) with the post_id of a number, you do it with the text.

    Further details: Google 'Keyword Slugs'.
     
    darrenbeige, Feb 8, 2009 IP
  8. mdrobiul

    mdrobiul Peon

    Messages:
    186
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    My problem is here. I know how to make clean url using rewrite engine for //www.sitename.com/index.php?ca...cat=Serverside

    but if my current site url is generated like this: user.php?id.250 and news.php?id.450 or download.php?id.450

    I want to make clean url from content (title in the content) from user.php?id.250 and news.php?id.450

    .com/download.php?id.450.54, will be .com/download/games/nfs-2/

    note that "nfs-2" and "games" did not come from url and it came from the page content..

    What I want to do can be called same like this forum thread as id to keyword..

    Can you please refer us to article or project ?
     
    mdrobiul, Feb 8, 2009 IP
  9. darrenbeige

    darrenbeige Peon

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Wordpress does it in one of its plugins. Look at the source or Google "use of slug mod rewrite"...

    Sorry I can't give cut and paste code, but it depends on how your site is setup...
     
    darrenbeige, Feb 9, 2009 IP