Forum Moderators: phranque

Message Too Old, No Replies

custom extensions ala arstechnica's .ars files

What's the trick to getting this to work?

         

sigmahawk

12:22 am on Apr 8, 2009 (gmt 0)

10+ Year Member



After much googling and trying many combinations of addtype and addhandler and sethandler and server-parsed and all that, i have yet to find a way to enable my just extension to be treated as a .php file.

Help please!

jdMorgan

1:16 am on Apr 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's not difficult, but neither is it something that someone can provide a three-line answer to.

Please post exactly *what* you have tried, along with where you put the code, and whether you re-started your server and flushed your browser cache before testing. This will save a lot of time -- both for you and for anyone contemplating trying to answer.

Thanks,
Jim

sigmahawk

2:41 am on Apr 8, 2009 (gmt 0)

10+ Year Member



I have tried:
AddType application/x-httpd-php .blah
and
SetHandler application/x-httpd-php .blah
and
<FILES *.blah>
SetHandler application/x-httpd-php
</FILES>
and
AddHandler server-parsed .blah
AddHandler application/x-httpd-php .blah
and
AddHandler server-parsed .blah
SetHandler application/x-httpd-php .blah
and
<Files *.blah>
AddType application/x-httpd-php
</Files>

I've tried clearing my cache when doing this, but not restarting Apache as from what i understand editing .htaccess should take effect when i try to load up the file in my browser right away. And i've tried with and without the leading . as well. I even tried using cpanel's built in tools for adding the handlers and types but that didn't seem to work either.

sigmahawk

5:30 am on Apr 8, 2009 (gmt 0)

10+ Year Member



Just to clarify (the edit time cut me off) when i do try any of the above, navigating to my page results in my browser trying to download the file.

coopster

12:52 pm on Apr 8, 2009 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, sigmahawk.

The proper way to get PHP to parse a file with any given extension is to use the appropriate handler. By default for PHP5 you accomplish this by adding the extension to the php handler:

# For PHP 5 do something like this, 
# separating file extensions with a single space:
AddHandler php5-script php ars htm html

Of course, it all depends on how your server is configured but as I said, this is the default handler.

jdMorgan

12:57 pm on Apr 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you have basically copied the settings for real PHP files, changed the file extension to .blah, and added that copied/modified code back into the same file and code block that you copied it from, then the likely cause is that your PHP is installed as cgi instead of as a handler.

You could try leaving all of that out, and doing the following:
1) Name the files as .php, but link to them as .blah URLs on all of your pages.
2) Use mod_rewrite to internally rewrite requests for .blah URLs to .php files.

Jim

sigmahawk

2:28 pm on Apr 8, 2009 (gmt 0)

10+ Year Member



Ok, so, option 1 (coopster), adding the handler, worked half-way. Instead of being asked to download the file it's being loaded up in the browser as plaintext. Option 2 (jdmorgan) also works quite well, but i am curious as to why adding the handler didn't work. Also, the page i'm trying use the custom extension for is a self-submitting form, and when the user submits the page and it reloads with the submitted info, it comes back as .php instead of .blah, any thoughts?

Thankyou guys!

[edited by: sigmahawk at 3:01 pm (utc) on April 8, 2009]

Caterham

2:37 pm on Apr 8, 2009 (gmt 0)

10+ Year Member



but i am curious as to why adding the handler didn't work.

Are you sure that there is a handler for 'application/x-httpd-php'? Either mod_php or some self-defined handler name (fastCGI etc.).

jdMorgan

5:16 pm on Apr 8, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



it reloads with the submitted info, it comes back as .php instead of .blah, any thoughts?

1) Name the files as .php, but link to them as .blah URLs on all of your pages.

You must modify the links on *all* of your pages, including the POST link in your form, to reference .blah URLs.

Jim