Page 1 of 1

Apache and spaces for vitual directories

Posted: Tue Jun 21, 2005 7:27 pm
by twrofpwr
I know this isn't a php question directly (well it might just be) but I have virtual directories set up that need to have spaces... how can this be handled? with %20? or special characters?? %20 doesn't seem to work though with apache. I know you can have unix directories with spaces or even windows... But can you have virtual directories with spaces Thanks for your help,

Jeff

Posted: Wed Jun 22, 2005 7:33 am
by timvw
What do you mean with a "virtual directory" ?

On most operating systems it's a matter of using " " to place the name.

Code: Select all

mkdir &quote;/home/timvw/My Documents&quote;
deltree &quote;F:/Documents And Settings/timvw/My Documents&quote;
If you want to provide a hyperlink to a name.. You need to look at
http://www.php.net/urlencode.

Posted: Wed Jun 22, 2005 12:56 pm
by nielsene
Virtual Directories: normally means the use of the Apache ForceType directive to allow one "root" script to handle a collection of pages, with some of the parameters masquerading as directories. As an example from my site, the URL

Code: Select all

http://localhost/~nielsene/cib/main-dev/results/details/2642/Newcomer/Standard/YCN%20Points
the script is actually "details" in the results directory. All of the later "directories" are virtual -- "2642","Newcomer","Standard","YCN Points" and are parsed into parameters for the queries/display.

Details is not a ".php" simply "details"
the results directory has an .htaccess file with

Code: Select all

<Files details>
  ForceType application/x-httpd-php
</Files>
and Apache automagically back chains to try to find a matching script.

Regarding the OP question about spaces, as the example above shows the space is encoded as %20. So far, I've had success with using the space as a spance and the browser/php has always auto-converted for me. I know I need to look into it more to know why, but....

Posted: Wed Jun 22, 2005 5:21 pm
by Chris Corbyn
I'm guessing you're using IIS since this uses the term "Virtual Directories" to mean the same thing Apache does by "Aliases"...

In Apache's httpd.conf you need to add a line:

Code: Select all

Alias /aliased-path/ /actual-path/

#or if it contains spaces
Alias &quote;/aliased path/&quote; &quote;/actual path/&quote;
In IIS (using the snap-in) you simply right click over the directory (or website) and choose "Make Virtual Directory" -> The wizard will talk you through the rest.

OK now to parse .html as PHP... you need to add a handler for this type of file in httpd.conf...

Code: Select all

AddHandler php-script .php .html
In IIS you need to do the same thing but I dont remember where it is in the snap-in control.

Either way... then answer to your question is yes... if the path contians spaces you will have to use it's URL encoded format to view it in a web browser. http://www.yourdomain.com/aliased%20path/

I think that's what you were referring to right?

Note: PHP will ignore such directives... you'll have to use absolute real paths in any code you write ;)

Posted: Wed Jun 22, 2005 6:02 pm
by twrofpwr
But how are the spaces encoded in the apache configuration file for directories which you want spaces in?

:)

Posted: Thu Jun 23, 2005 4:13 am
by Chris Corbyn
They aren't encoded in the config file... I just showed you above. Just type the URL with the spaces in but make sure you enclose the path with double quotes so that the spaces are read as part of the path. Nothing more to it ;)