Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

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?

Report this thread to moderator Post Follow-up to this message
Old Post
Purple Haze
09-28-04 01:56 AM


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
> 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/direc...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



Report this thread to moderator Post Follow-up to this message
Old Post
Thomas Mlynarczyk
09-28-04 01:56 PM


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
> 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 whate
ver.

$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
shawn@glassgiant.com
http://www.glassgiant.com

Report this thread to moderator Post Follow-up to this message
Old Post
Shawn Wilson
09-29-04 02:26 AM


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

Report this thread to moderator Post Follow-up to this message
Old Post
Berislav Lopac
09-29-04 03:45 PM


Re: Virtual Directories?
Berislav Lopac wrote:

> On Mon, 27 Sep 2004 22:35:08 GMT, Purple Haze wrote:
>
> 
>
>
> a) mod_rewrite on Apache
> b) custom 404 error page

c) ISAPI_rewrite on IIS

--
Justin Koivisto - spam@koivi.com
http://www.koivi.com

Report this thread to moderator Post Follow-up to this message
Old Post
Justin Koivisto
09-29-04 03:45 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP Language archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:36 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.