Jump to content

getting index basename from an URL


scarhand

Recommended Posts

i think really the only way is to compile a list say index.html index.htm index.php index.pl default.asp default.aspx and so on

and just try everyone until you get a 200 response code.

if you go do http://domain.com/ and get a 302(redirect) then you will be getting redirected to there index page and you should use that.

 

Scott.

 

i think really the only way is to compile a list say index.html index.htm index.php index.pl default.asp default.aspx and so on

and just try everyone until you get a 200 response code.

if you go do http://domain.com/ and get a 302(redirect) then you will be getting redirected to there index page and you should use that.

 

Scott.

 

 

thats what i have originally done but i was wondering if there is a better way.

heres my current code:

 

$url is a validated URL (with regex)

file_extension is a command to get the file extension from the URL

url_exists is a command to validate the URL

 

<?php

    $CONFIG['extensions'] = Array();
    $CONFIG['extensions'][] = 'htm';
    $CONFIG['extensions'][] = 'html';
    $CONFIG['extensions'][] = 'shtm';
    $CONFIG['extensions'][] = 'shtml';
    $CONFIG['extensions'][] = 'css';
    $CONFIG['extensions'][] = 'js';
    $CONFIG['extensions'][] = 'vbs';
    $CONFIG['extensions'][] = 'php';
    $CONFIG['extensions'][] = 'php3';
    $CONFIG['extensions'][] = 'php4';
    $CONFIG['extensions'][] = 'php5';
    
    $CONFIG['indexfile'] = Array();
    $CONFIG['indexfile'][] = 'index.htm';
    $CONFIG['indexfile'][] = 'index.html';
    $CONFIG['indexfile'][] = 'index.shtm';
    $CONFIG['indexfile'][] = 'index.shtml';
    $CONFIG['indexfile'][] = 'index.php';
    $CONFIG['indexfile'][] = 'index.php3';
    $CONFIG['indexfile'][] = 'index.php4';
    $CONFIG['indexfile'][] = 'index.php5';

    $ext = file_extension($url);
    
    if (!in_array($ext, $CONFIG['extensions']))
    {
      if (substr($url, -1) != '/')
        $url = "$url/";
      
      foreach ($CONFIG['indexfile'] as $ind) 
      {
        if (url_exists($url.$ind))
          $url = $url.$ind;
      }
    }

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.