Web Hosting Talk







View Full Version : PHP to HTML with HTACCESS


UrlGuy
01-31-2006, 07:46 PM
Hi,

I'm helping a friend who runs a free-hosting service.
To prevent abuse he would like to disable all php/perl/cgi (and similar) scripts.

I thought using htaccess for this would be a good idea. I have already used htaccess to force ads in header/footer of their pages.

The problem is, I dont know how to. I've asked in different IRC rooms and looked on apache page, without any luck.

The current .htaccess file now looks like this:


AddHandler headered .htm
AddHandler headered .html

Action headered http://localhost/ads/ads/config.php


This code is just for the ads.

I have tried adding this:

AddType text/plain php

which were supposed to parse php as text.
This doesn't work. When I use the above, all pages give 404 not found error.

I also need to have php enabled on a few files, which is required for the free-hosting services script which sets up the accounts.
I also don't know what directories to do this to, as they are being setup automaticly.

So the htaccess should have this rule to affect ALL files, except a few specified ones (which are the hosting script files)

Anyone know how I can parse php as text or html with a .htaccess?

Thanks in advance for all replies!

Best rgds,
~urlguy

Dan L
01-31-2006, 08:11 PM
ForceType text/html .php
<Files file1,file2>
ForceType application/x-httpd-php
</Files>

I think that's it

UrlGuy
01-31-2006, 08:43 PM
Hi, thanks for your reply!

I now have this

AddHandler headered .htm
AddHandler headered .html
AddType text/plain php

Action headered http://localhost/ads/config.php

ForceType text/html .php
<Files myfile.html>
ForceType application/x-httpd-php
</Files


Although this gives me 'Internal Server Error'.
Any idea why?

Oh and btw, I dont want to parse only some php files as html, but all files, except a few I choose.

Thanks again.

~urlguy

Josh1billion
02-01-2006, 11:59 AM
Wow, this information is just what I needed myself.

Thanks very much!

UrlGuy
02-01-2006, 12:04 PM
Wow, this information is just what I needed myself.

Thanks very much!

Did you get this to work? If so, how?
Thanks.

UrlGuy
02-01-2006, 05:17 PM
Ok, I now have this:


AddType text/plain .php
AddType text/plain .php3
AddType text/plain .pl
AddType text/plain .cgi

<Files phpinfo.php>
RemoveType text/plain
</Files>



This is supposed to parse all php/php3 etc. files as plain-text. The RemoveType is supposed to undo this action to phpinfo.php.

This works perfect, only that the RemoveType doesn't seem to work. Well phpinfo.php is still being parsed as plain-text.

Can anyone see what's wrong with the above code?

Thanks!

Josh1billion
02-01-2006, 05:56 PM
Did you get this to work? If so, how?
Thanks.
Nope, I'm talking about the ad enforcement. I've been looking for a way to do this, and until I saw this thread, I didn't know it was possible through .htaccess.

UrlGuy
02-01-2006, 06:53 PM
Nope, I'm talking about the ad enforcement. I've been looking for a way to do this, and until I saw this thread, I didn't know it was possible through .htaccess.

Oh, ok. Then you should read this tutorial which atleast helped me alot; http://www.developertutorials.com/tutorials/php/htaccess-wrappers-php-050525/page2.html

Josh1billion
02-15-2006, 07:27 PM
Oh, ok. Then you should read this tutorial which atleast helped me alot; http://www.developertutorials.com/tutorials/php/htaccess-wrappers-php-050525/page2.html
Thank you so much for that link.. it's exactly what I spent a lot of time Googling for a few weeks ago and never found! :)

Hey.. to show my gratitude, if you want, I can send you a PHP script that I wrote myself to delete PHP files from a given directory. You can use this to disable PHP in users' accounts-- although it may not be the cleanest way of disabling PHP, it will get the job done if you don't care if a user has a PHP file uploaded for just one minute (depending on your security, it might not even matter if they do) and then you can set the script to be run every minute through cron jobs or something. I'm still looking for a way to run the script through Cron Jobs though successfully.. I found a page online which told me the command to enter into Cron, but it didn't work, I guess.. think maybe my Cron isn't working or something.

Anyway, if you want that script, message me on AIM (Josh1billion) or drop me an e-mail at Josh (at) lunarzone (dot) net.