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.

Problem with .htaccess or/and php code

Discussion in 'PHP' started by subfor, Aug 29, 2009.

  1. #1
    Hello,

    I have problem with website http://concord.websitewelcome.com/~justoco/adult/ (no adult content, I swear!). The problem is that links like 'Videos', 'Photos' and all the rest is not working. I believe it is the problem with .htacess or/and loader.php file. The problem is not due my hosting. All the required functions are supported.

    Please post some suggestions. Thank you.

    .htaccess :

    #####################################
    # Comment the 2 lines below if the server returns 500 errors!
    Options -Indexes
    Options +FollowSymLinks
    
    # Uncomment following lines if Apache doesnt support MultiViews!
    #<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* loader.php [L,QSA]
    
    #######################################
    Code (markup):
    loader.php:

    <?php
    //die('Only enable this script if you dont have support for MultiViews');
    $relative = '';
    $loaders  = array(
        'ajax' => 1,
        'album' => 1,
        'albums' => 1,
        'blog' => 1,
        'blogs' => 1,
        'captcha' => 1,
        'categories' => 1,
        'community' => 1,
        'confirm' => 1,
        'error' => 1,
        'feedback' => 1,
        'feeds' => 1,
        'game' => 1,
        'games' => 1,
        'index' => 1,
        'invite' => 1,
        'loader' => 1,
        'login' => 1,
        'logout' => 1,
        'lost' => 1,
        'mail' => 1,
        'notice' => 1,
        'notices' => 1,
        'photo' => 1,
        'requests' => 1,
        'search' => 1,
        'signup' => 1,
        'static' => 1,
        'stream' => 1,
        'upload' => 1,
        'user' => 1,
        'users' => 1,
        'video' => 1,
        'videos' => 1,
    	'edit' => 1
    );
    
    $query      = ( isset($_SERVER['QUERY_STRING']) ) ? $_SERVER['QUERY_STRING'] : NULL;
    $request    = str_replace($relative, '', $_SERVER['REQUEST_URI']);
    $request    = str_replace('?' .$query, '', $request);
    $request    = explode('/', trim($request, '/'));
    if (isset($request['0'])) {
        $page   = $request['0'];
        if (isset($loaders[$page])) {
            require $page. '.php';
        } else {
    		header('HTTP/1.0 404 Not Found');
      		die();
    	}
    } else {
    	header('HTTP/1.0 404 Not Found');
        die();
    }
    ?>
    PHP:

     
    subfor, Aug 29, 2009 IP
  2. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you're trying to fin the path you're going bout it the wrong way.

    Try this.

    
    $base_path = "/~justoco/adult/";
    $loaders  = array(
        'ajax','album','albums','blog','blogs','captcha','categories',
        'community','confirm','error','feedback','feeds','game','games',
        'index','invite','loader','login','logout','lost','mail','notice',
        'notices','photo','requests','search','signup','static','stream',
        'upload','user','users','video','videos','edit'
    );
    
    $url = parse_url('http://'.$_SERVER["HTTP_HOST"].$_SERVER['REQUEST_URI']);
    $path = $url['path'];
    $query = $url['query'];
    
    if($path != $base_path)
         $path = sub_str($path, strlen($base_path)); //snips the first / off the path
    else
        $path = "/"; //sets it as the 'base' if you want a default page 
     
    if(array_search($path, $loader) !== false)
         require '{$path}.php';
    elseif($path == "/")  //snip this line if you don't want a default
         require 'default.php'; // snip this line if you don't want a default
    else
    {
         header('HTTP/1.0 404 Not Found'); die;
    }
    
    PHP:
     
    Last edited: Aug 29, 2009
    kblessinggr, Aug 29, 2009 IP
  3. Chemo

    Chemo Peon

    Messages:
    146
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    
    RewriteEngine On
    RewriteBase /~justoco/adult/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .* loader.php [L,QSA]
    
    Code (markup):
    Note the RewriteBase addition.
     
    Chemo, Aug 29, 2009 IP
  4. kblessinggr

    kblessinggr Peon

    Messages:
    539
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #4
    :p That' too :p

    That makes me wonder though. Will the request_URI begin with /~justoco/adult/ ? if so these are new modified lines for the code I pasted above:


    
    if($path != "/~justoco/adult/")
         $path = sub_str($path, 16); //snips the first / off the path
    else
        $path = "/"; //sets it as the 'base' if you want a default page
    
    PHP:
    [edited the original]
     
    kblessinggr, Aug 29, 2009 IP
  5. Chemo

    Chemo Peon

    Messages:
    146
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #5
    At the top of the script he would need to define the relative variable to look like this:
    
    $relative = str_replace($_SERVER['DOCUMENT_ROOT'], '', __FILE__);
    
    PHP:
    This will cascade down into the code below it and should make it functional. However, that's one piss poor front end controller.
     
    Chemo, Aug 29, 2009 IP
  6. subfor

    subfor Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thank You guys!
    Everything went smoothly.
    Problem was with .htaccess (added RewriteBase /~justoco/adult/ as Chemo suggested)
     
    subfor, Aug 29, 2009 IP