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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;
      }
    }

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.