simple mod_rewrite issue

Discussion in 'Apache' started by monged, Jan 21, 2008.

  1. #1
    I use the following PHP code to include files within my site.

    <?php
    $pid = @$_GET["pid"];
    $exists = file_exists($pid. ".php") ? 1: 0;
    if($exists) @include($pid. ".php");
    else{
    if($pid){
    @include("404.php");
    }
    else @include("main.php");
    }
    ?>

    my URL structure is like...

    domain.com/index.php?pid=foldername/pagename

    I want my URL structure to be like...

    domain.com/foldername/pagename

    I have done it before but due to the website being rolled back while i was away in Egypt the .htaccess file is now blank :confused:

    Any help appreciated.
     
    monged, Jan 21, 2008 IP
  2. MaverickW

    MaverickW Peon

    Messages:
    16
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think the htaccess file should look something like:

    RewriteEngine On
    RewriteRule /(.*)/ index.php?pid=$1 [R]

    On a side note, never take filenames from query strings. It is a serious security hazard.
     
    MaverickW, Jan 21, 2008 IP
  3. monged

    monged Banned

    Messages:
    86
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Cheers MaverickW but that doesn't work :(
     
    monged, Jan 21, 2008 IP