vk101
04-05-2005, 04:18 PM
When hosting a site, is it possible to send a file to a browser without a corresponding extension like .html, .jsp, .asp, .php, etc, but still have the browser know what kind of file it is?
I'd imagine that the extension needs to be present on the file itself (otherwise the browser has really no way of knowing), but is there a way to alias the filenames in Apache so that a link to your site would be www.domain.com/hi but it would automatically load up www.domain.com/hi.asp, for example?
(I know this would be possible by creating a new folder for every single page, but that would be really inefficient. Is there a way of doing this as described above?)
I basically want to not have people see the extension from the browser address bar itself. Is it possible to hide these extensions somehow?
I wonder if this is possible. Thanks a lot.
the_pm
04-05-2005, 04:27 PM
There's talk about this happening in the future, about all file extensions being eradicated. This includes not only HTML document extensions, but also downloadable files and image files too. I'll dig around for more info on this, but you're thinking along the lines of W3 with your speculations :)
X-TechMedia
04-05-2005, 06:37 PM
You could put
AliasMatch ^/nav/.* /home/content.php
into your httpd.conf so that when http://domain.com/nav/ is accessed it actually calls content.php
Not sure if thats what you meant though....
GopherDesign
04-05-2005, 07:26 PM
Try
Make a .htaccess file
Add this in it for php:
<files directory>
SetHandler application/x-httpd-php
</files>
vk101
04-05-2005, 08:38 PM
Thanks for the suggestions!
So with the suggestion directly above this message, would ALL files within the directory specified be handled as PHP files, for instance?
Is there any way to handle files on a file-by-file basis, or is it only possible by handling all files within a particular directory all in the same way?
Thanks.
BigBison
04-06-2005, 12:03 AM
Brush up on content negotiation in HTTP 1.1, this stuff's built right in. If you're using Apache 1.3, here's the relevant documentation:
http://httpd.apache.org/docs/content-negotiation.html
Enable mod_negotiation. Now, let's say a request comes in for "example.com/images/photo_one". You do have your graphics files in their own subdirectory, right? Assume you have photo_one.gif, photo_one.jpg and photo_one.png in the "images" subdirectory. Apache will choose which file to serve based on which graphics format is preferred by the requesting client. If the client doesn't state a preference, your preferred format is served. You don't need to have more than one option, and you don't need to have an images subdirectory. If you don't use an images subdir, make sure no images have the same name as any html pages.
BigBison
04-06-2005, 12:33 AM
Originally posted by vk101
Is there any way to handle files on a file-by-file basis, or is it only possible by handling all files within a particular directory all in the same way?
Let's say you have a directory of .html and .php files for your site. The .html files are static pages, the .php files are dynamic. You want your URL to resemble "example.com/page". If page.html exists, serve it. If page.html doesn't exist, and page.php does, the script is run. If no file of that name exists with any extension, of course a 404 error is returned.
How to set this up? Enable mod_negotiation. That's it.