Professional Web Applications Themes

Virtual Directories? - PHP Development

I have seen websites that use a sort of "virtual directory" system... Lets say when you click on something it goes to [url]http://www.example.com/scripts/php/[/url] Neither the scripts directory nor the php directory physically exisit on the server, does anyone know how this is done?...

  1. #1

    Default Virtual Directories?

    I have seen websites that use a sort of "virtual directory" system...

    Lets say when you click on something it goes to
    [url]http://www.example.com/scripts/php/[/url]

    Neither the scripts directory nor the php directory physically exisit on
    the server, does anyone know how this is done?
    Purple Haze Guest

  2. #2

    Default Re: Virtual Directories?

    Also sprach Purple Haze:
    > I have seen websites that use a sort of "virtual directory" system...
    >
    > Lets say when you click on something it goes to
    > [url]http://www.example.com/scripts/php/[/url]
    >
    > Neither the scripts directory nor the php directory physically exisit
    > on the server, does anyone know how this is done?
    The Apache web server can automatically transform a path into another using
    the Alias directive in its configuration files:

    Alias /scripts/php c:/just/another/directory

    So, when you type [url]http://www.example.com/scripts/php/[/url], Apache goes to
    c:/just/another/directory instead.

    However, there is a much more flexible solution with Apache, it's called
    mod_rewrite. This is an Apache module that allows you to transform
    (re-write) URLs whichever way you wish, depending on the URL and the
    environment. Example:

    RewriteEngine On
    RewriteRule ^scripts/php/(.*)$ /my/own/directory/myscript.php?page=$1

    So, when you type [url]http://www.example.com/scripts/php/welcome.html[/url], the above
    rule (to be placed either in the Apache's config file or an .htaccess file)
    will transform this into
    [url]http://www.example.com/my/own/directory/myscript.php?page=welcome.html[/url]. The
    syntax of mod_rewrite uses regular expressions and is a bit complicated (I'm
    not even sure if my above example will actually work, but it illustrates the
    principle.) But it can be a very powerful tool.

    Greetings,
    Thomas


    Thomas Mlynarczyk Guest

  3. #3

    Default Re: Virtual Directories?

    Purple Haze wrote:
    >
    > I have seen websites that use a sort of "virtual directory" system...
    >
    > Lets say when you click on something it goes to
    > [url]http://www.example.com/scripts/php/[/url]
    >
    > Neither the scripts directory nor the php directory physically exisit on
    > the server, does anyone know how this is done?
    Hey,

    [url]http://www.example.com/scripts/php/[/url]

    1. Create a file called "scripts" in the web root.


    2. Make a .htaccess file to force Apache to interpret "scripts" as PHP

    <Files scripts>
    ForceType application/x-httpd-php (going from memory. Google "ForceType")
    </Files>


    3. Manually get the trailing bits and use them to search a database or whatever.

    $possiblevalues = array('php', 'cgi', 'perl', 'asp');
    $trailingbits = preg_replace('/^scripts\//', '', $_SERVER['REQUEST_URI']);
    if (!in_array($trailingbits, $possiblevalues))
    show_my_error('Invalid script type');
    else
    list_scripts($trailingbits);

    Shawn

    --
    Shawn Wilson
    [email]shawnglassgiant.com[/email]
    [url]http://www.glassgiant.com[/url]
    Shawn Wilson Guest

  4. #4

    Default Re: Virtual Directories?

    On Mon, 27 Sep 2004 22:35:08 GMT, Purple Haze wrote:
    > I have seen websites that use a sort of "virtual directory" system...
    >
    > Lets say when you click on something it goes to
    > [url]http://www.example.com/scripts/php/[/url]
    >
    > Neither the scripts directory nor the php directory physically exisit on
    > the server, does anyone know how this is done?
    a) mod_rewrite on Apache
    b) custom 404 error page
    Berislav Lopac Guest

  5. #5

    Default Re: Virtual Directories?

    Berislav Lopac wrote:
    > On Mon, 27 Sep 2004 22:35:08 GMT, Purple Haze wrote:
    >
    >
    >>I have seen websites that use a sort of "virtual directory" system...
    >>
    >>Lets say when you click on something it goes to
    >>[url]http://www.example.com/scripts/php/[/url]
    >>
    >>Neither the scripts directory nor the php directory physically exisit on
    >>the server, does anyone know how this is done?
    >
    >
    > a) mod_rewrite on Apache
    > b) custom 404 error page
    c) ISAPI_rewrite on IIS

    --
    Justin Koivisto - [email]spamkoivi.com[/email]
    [url]http://www.koivi.com[/url]
    Justin Koivisto Guest

Similar Threads

  1. No JRunScripts virtual directories (?)
    By Bill Gordon in forum Coldfusion - Getting Started
    Replies: 5
    Last Post: June 9th, 08:05 PM
  2. Creating Virtual Directories
    By michaelmuller in forum Coldfusion - Advanced Techniques
    Replies: 5
    Last Post: July 4th, 07:27 PM
  3. https and virtual directories
    By Dru Snyder in forum ASP.NET Security
    Replies: 0
    Last Post: March 15th, 04:31 PM
  4. virtual directories and IIS
    By Ali in forum ASP.NET Web Services
    Replies: 1
    Last Post: November 26th, 04:52 AM
  5. Replies: 2
    Last Post: July 30th, 07:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139