Code Comments
Programming Forum and web based access to our favorite programming groups.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?
Post Follow-up to this messageAlso 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
Post Follow-up to this messagePurple 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
Post Follow-up to this messageOn 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
Post Follow-up to this messageBerislav 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
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.