Virtual Directories?

Ask a Question related to PHP Development, Design and Development.

  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. Similar Questions and Discussions

    1. https and virtual directories
      I've never done a login to a website so please bear with me. What is the best way to go about this? Do I put all of the pages in a subdirectory...
    2. No JRunScripts virtual directories (?)
      The CF7 document 'Configuring Web Servers' says that I should have a virtual directory called JRunScripts in each of my IIS websites. I upgraded...
    3. nested virtual directories
      I am using the Fiefdom techniques ( a seperation of concerns pattern ). I have 2 asp.nET projects, each with their own virtual dir 1....
    4. virtual directories and IIS
      I created a new directory on my hard drive C:\test. I mapped a virtual directory called MyWeb to this directory. Now when I try to create an...
    5. Using virtual directories for common directories (scripts, images, styles, etc.)
      Hi, (sorry for the crosspost, I wasn't sure which was the best place to put this). I was just thinking about something and wondered if any of...
  3. #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

  4. #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]shawn@glassgiant.com[/email]
    [url]http://www.glassgiant.com[/url]
    Shawn Wilson Guest

  5. #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

  6. #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]spam@koivi.com[/email]
    [url]http://www.koivi.com[/url]
    Justin Koivisto Guest

Posting Permissions

  • You may not post new threads
  • You may 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