473,323 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Virtual Directories?

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

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

Neither the scripts directory nor the php directory physically exisit on
the server, does anyone know how this is done?
Jul 17 '05 #1
6 2404
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
http://www.example.com/scripts/php/

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 http://www.example.com/scripts/php/, 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 http://www.example.com/scripts/php/welcome.html, the above
rule (to be placed either in the Apache's config file or an .htaccess file)
will transform this into
http://www.example.com/my/own/direct...e=welcome.html. 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
Jul 17 '05 #2
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
http://www.example.com/scripts/php/

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


Hey,

http://www.example.com/scripts/php/

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
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #3
Nice solution, anyway: There's a slightly better way ;)

Shawn Wilson <sh***@glassgiant.com> wrote:
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>
<Files scripts>
ForceType application/x-httpd-php
AcceptPathInfo On
</Files>

Shawn Wilson <sh***@glassgiant.com> wrote: 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);


Use
$trailingbits = $_SERVER['PATH_INFO'];
instead.

I've used a similar script, the sources are:
<http://test.dangerouscat.net/download/.htaccess>
<http://test.dangerouscat.net/download/download>
(The script itself is located in /download, therefore you will see that it
works ;))
--
Simon Stienen <http://dangerouscat.net> <http://slashlife.de>
»What you do in this world is a matter of no consequence,
The question is, what can you make people believe that you have done.«
-- Sherlock Holmes in "A Study in Scarlet" by Sir Arthur Conan Doyle
Jul 17 '05 #4
Simon Stienen wrote:

Nice solution, anyway: There's a slightly better way ;)
<snip>
<Files scripts>
ForceType application/x-httpd-php
AcceptPathInfo On
</Files>
<snip>
Use
$trailingbits = $_SERVER['PATH_INFO'];
instead.


<snip>

That is a bit cleaner. Wish I'd known...

Shawn
--
Shawn Wilson
sh***@glassgiant.com
http://www.glassgiant.com
Jul 17 '05 #5
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
http://www.example.com/scripts/php/

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
Jul 17 '05 #6
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
http://www.example.com/scripts/php/

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 - sp**@koivi.com
http://www.koivi.com
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mark Hoagland | last post by:
I've got a scenario with a web application where I must access the virtual directory being accessed from within the Application_OnStart event handler. Specifically, I have a series of IIS virtual...
5
by: George Hester | last post by:
If I have 1 Virtual Dirctory with 2 different subfolders are these 2 different folders different virtual folders? Or if I have 2 different Virtual Directories each containing a subfolder are these...
3
by: pleaseHelp | last post by:
To better manage our secure site we just separated the registration and checkout sections of our web into separate virtual directories. These new virtual directories are on the same server as the...
2
by: Jeffry van de Vuurst | last post by:
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 you has some ideas about this. I'm using the...
4
by: Michelle | last post by:
I have a website with 6 virtual directories under it who dont "see" the bin/ directory in the root. If I create a /bin directory in each virtual directory and then copy my dll's in there, it...
1
by: Mark | last post by:
In our root web site, we have roughly 100 folders. 10 of these are virtual directories. The other 90 folders are a mix - some contain static HTML content. Others contain subfolders and...
4
by: Chuck P | last post by:
Using vs05 and making an asp.net 2.0 website. We use VSS and have everything organized like this SolutionName Documents Code WebProjectName1 WebServiceProjectName1
2
by: Angelo Cook | last post by:
how do you prevent the publishing of virtual directories in VS 2005. I have been using VS2003 and developing websites for years. I have been using virtual directories for images, icons, styles...
4
by: =?Utf-8?B?SmVmZiBCZWVt?= | last post by:
Best way I can think to describe this is through an example. I have a virtual directory, let's call it "MyVirtualDirectory" that maps to \\MyServer\Shared. I have a path that is...
4
by: Paul F | last post by:
Im confused about the difference(s) between virtual directories and physical directories in IIS. Any ideas? *** Sent via Developersdex http://www.developersdex.com ***
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.