Forum Moderators: phranque
This is the directive I put in the .htacess file in my main directory:
<Files filename>
ForceType application/x-httpd-php
</Files>
The directive successfully forces the file to be read as a PHP file when I call it without any trailing variables (http://www.website.net/filename). But when I add additional URI info (http://www.website.net/filename/variable1/variable2), I get a 404 error. (FilesMatch doesn't work either.)
Any idea why I'm encountering this problem? I've successfully used the ForceType directive in this exact same way on two other sites, using this Evolt article [evolt.org] as a guide. Not sure why it's tripping me up now.
Thanks in advance for the help.
Welcome to WebmasterWorld!
The Filesmatch directive in the article you cite seems to be incorrect; It should read
<FilesMatch "^article">
Note that there is no end-anchor ($). If the end-anchor is included, then only a single file named "article" would be matched.
Hoever, I don't see how it would work either way. <Files> and <FilesMatch> are used to control the server based on the "basename" -- that part of the URL following the last slash in the URL. As an example, in the URL-path "/article/200206072", only "200206072" is the basename.
You might want to look into other ways of doing this. For example, you can use mod_rewrite to both re-map the URL to your content and set the MIME-type at the same time using the [T] flag of RewriteRule.
Jim
Thanks so much for the fast reply. I will definitely switch over to a system using mod_rewrite.
On my other website (the one where I'm already using the ForceType directive), do you think it's possible that search engine bots are encountering errors when they try to request pages? I have had quiet a bit of trouble with proper optimization of my site's AdSense ads. I wonder if this could be the culprit.
Thanks again!
Jim
I got the following response to a page using the ForceType protocol:
HTTP/1.1 200 OK
Date: Thu, 14 Jul 2005 02:00:30 GMT
Server: Apache/2.0.46 (Red Hat)
Accept-Ranges: bytes
X-Powered-By: PHP/4.3.2
Connection: close
Content-Type: text/html
It seems, then, that the Files/ForceType approach can work. The mystery is why it's working on one site but not on another, when both are on the same server.
I'm not going to bother figuring it out, though. As you recommended, I'm just going to switch to a mod_rewrite solution.
Thanks again!