Click to See Complete Forum and Search --> : Virtual url path? I guess...
cjs50
08-19-2004, 01:26 PM
I am new to apache so I'll try and be somewhat clear as to what I am looking to do. I'm used to the microsoft world and trying to get away from it.
I have a web server setup with apache 1.3.31 and php 4.3.8. I'm trying to figure out w I might be able to trap or intercept the url path if it is possible.
To make myself a bit clear. I want to have any url path point to a single directory location. (ie: http://domain/home, http://domain/, http://domain/folder/folder all pointing to say /apache/www_docs) I want to be able to use PHP to parse the url path and have it generate the page based on the url specified.
I am somewhat familiar to the configuration of apache and php. I'm simple looking for a setting to point all url requests to a single folder path on the web server.
Thanks,
Cliff
sharth
08-19-2004, 01:52 PM
Probably would have to do it within apache, not php... And you could probably do it with a virtual host and wildcards.
cjs50
08-19-2004, 02:08 PM
I figured I would have to use virtual hosts. Currently I would enter in for ex: http://localhost and I'll get to my index.php of course but if I enter in http://localhost/home I'll get a 404 since there is no home folder within the document root dir.
Is there a possibility of capturing the 404 error before it gets passed back to the client browser.
I noticed the <Location> section. Looks like the possibility of redirecting an error code to a web path?
Correct me if I am wrong, does the service have to be restarted if you make a change to httpd.conf file? I'm to make things a bit more dynamic. I'm trying to get away from static settings.
sharth
08-19-2004, 03:25 PM
Originally posted by cjs50
Correct me if I am wrong, does the service have to be restarted if you make a change to httpd.conf file? I'm to make things a bit more dynamic. I'm trying to get away from static settings. I have no access to a server to fiddle right now, but I know that you can specify the error page (the 404 page).
also, you can do, in most distros, a reload on the init script which will not kill the server, but update its config.
"/etc/init.d/apache reload" for debian
cjs50
08-19-2004, 05:22 PM
I found a site that gives quite a bit of info for this at:
http://phpbuilder.com/columns/tim20000526.php3
It's based on php3 but I'm sure still works. Still have to figure it out. I found how to redirect all 404 Not Found errors to a default location by adding this to the httpd.conf file. It redirects the 404 but still I don't get the result I am after.
<Location /*>
Allow from all
ErrorDocument 404 http://domain/index.php
</Location>
Unfortunately if you are using $_SERVER['PHP_SELF']; and $_SERVER['HTTP_HOST']; to query the browser domain and subfolder, it just simply redirects to the root dir and specifies still a static path.
I was hoping that it was just so simple. Tough being a newbie. :)
Thanks!
cjs50
08-19-2004, 06:10 PM
Using the above article I have gotten it to do something closer to the result I am looking for. In the httpd.conf file I added this:
<Location /local>
ForceType application/x-httpd-php
</Location>
I created a file local within the /htdocs/ folder and when I input http://domain/local it loads the local doc as a php file. This is fine and all if I wanted to create a file for every sub page or sub directory simulation. I am trying to figure out if it is possible to modify this by the following:
<Location /*>
ForceType application/x-httpd-php <---- if even needed
Document /index.php <---- is there a a document command
</Location>
I'm not familiar with all the sytax/commands to be able to be used in the httpd.conf. At least if I can specify a setting like this I may be able to direct all subfolders in a url to a file. Similar to above with a 404 redirection just I do not want to redirect. Just point to the script to use.
Thanks!
bwkaz
08-19-2004, 06:34 PM
You want mod_alias and/or mod_rewrite. Those modules might be Apache 2 only, though...
You can't do what you want with virtual hosts, because virtual hosting maps the same Apache server to a different directory (that's problem 1) on the hard drive depending on the domain name used to access the server (not the directory -- that's problem 2). Virtual hosts will allow http://localhost/ and http://yourhostname.yourdomain.tld/ to retrieve different pages (well, just pages from different directories), but it will NOT allow you to serve up both http://localhost/ and http://localhost/home/ from the same directory.
To do that, you use mod_rewrite, and add Alias sections to your Apache config file. Each Alias references the local-part of a URL (the stuff after the domain name), and maps it to a physical directory on the server. For example:
Alias /images/ "/var/www/images/" I think you also need a <Directory> section for any directory that you use a server alias to map a virtual path to, but you should have that already for the root path.
What these Alias directives do is they match a piece of the beginning of the URL as sent by the browser. When that matches, then Apache strips off that part of the URL and replaces it with the target of the Alias (then it uses that path to try to find the requested file). So for example, http://localhost/home/ could be mapped to /var/www/htdocs/ (which is going to be the same directory as http://localhost/ maps to) with an:
Alias /home/ "/var/www/htdocs/"
The slashes are important.
But again, this might require Apache 2. And it does require that the target of the alias is the same as the directory that the root of the web server maps to.
sharth
08-19-2004, 09:38 PM
mod_rewrite will work in both apache1 and apache2, and yeah, that would do the trick perfectly.