I want my shared web server to process ".ncs" files just like ".php" files.
I know this can be easily done by adding an entry in Apache Handler. Ref: http://php.net/manual/en/security.hiding.php
But as I have mentioned that I am using shared hosting, any changes made by me on Apache Handler will not work. Those lists are just for reference. I opened a ticket in my website provider's support panel and they told me that I should use .htaccess file for that. But I am unable to understand that how I may use .htaccess file to process .ncs files just like .php files.
You need to use a AddType handler on the htaccess of the root of your server:
AddType application/x-httpd-php .ncs
BUT if you're running PHP as CGI, you need to use AddHandler too:
AddType application/x-httpd-php .ncs
AddHandler application/x-httpd-php .ncs
Related
My apache runs php files with or without .php extension, How can I disable this and force apache to run php files only with .php extension. I don't want to use .htaccess, this might be an apache config. does anyone know how to disable this option?
Thanks for the answer but using Addtype as you mentioned did not ever work for me, all by itself, even in PHP 5..
Here's what I've tried that DOESN'T work with this version of PHP:
Options +ExecCGI
AddType application/x-httpd-php .php .nusuffix
AddHandler x-httpd-php5 .php .nusuffix
This worked for PHP 5. Now, does not.
This is for a hosted account, so I must do this via .haccess.
You can check your httpd.conf what extensions are configured, it need need to be following. if there is change in your file you can change it to following and restart the apache
AddType application/x-httpd-php .php
more details : https://wiki.archlinux.org/index.php/Apache_HTTP_Server
please add if anything is missing
I have few files whose extension is htm that i want to run as php using htaccess code
this is the htaccess code that i am using
AddHandler application/x-httpd-php5 .htm .php .html
this code work fine but now i change my hosting server in that this code not working.
i tried all these code but no one work
AddHandler application/x-httpd-php .htm .php .html
AddType application/x-httpd-php .html .htm
AddType application/x-httpd-php5 .html .htm
my new server says
cPanel Linux Hosting packages only support the SymLinksIfOwnerMatch option in the .htaccess file.
Please point me in right direction how can i run htm file as php on my server
I'm afraid it's a no-go then... If your hosting blocks the appropriate directives in your .htaccess, your only way to go would be to either blackmail or hack the provider, or change the extension from .htm to .php. As this is really a server-administration thing, and if the server administrator doesn't allow you, there is no way you can go around it...
A hacky solution would be to use rewrites to route .htm to .php files. But still then you'd need to rename your files from .htm to .php. This could be a solution if you're app routing isn't setup dynamically and your main concern is that the url's should not be changed. Although changed url's can be caught with 301 redirects.
I'm stuck trying to figure out what directives my htaccess file for a directory needs. To give a little background, I was messing around with AddType and AddHandler to try to get html files to run php in them. I was adding directives like:
AddType application/x-httpd-php .php .html
and
AddType application/x-httpd-php5 .php .html
That didn't work, so I tried adding handlers as well:
AddHandler x-httpd-php .php .html
and
AddHandler application/x-httpd-php .php .html
That still didn't give me what I wanted so I tried many combinations, like:
AddType application/x-httpd-php .php .html
AddHandler php-script .php .html
I even tried combinations with SetHandler
AddType application/x-httpd-php .php .html
AddHandler php-script .php .html
SetHandler application/x-httpd-php .php html
I tried every imaginable combination of AddType and AddHandler found on the web.
!===== This is important ======!
I realized that its not good practice to have php run your html files just so you can run php in the html. I am no longer trying to do that. The only reason I'm posting this part above is to give you an idea on some things I've changed. These changes were made to the htaccess file at a directory above the root.
!==============================!
Now that I'm no longer trying to run my php in html files I cleared the AddType, AddHandler, and SetHandler directives from the htaccess file. But now I get an internal server error when trying to run php files.
So I tried putting some stuff back. If I had a handle, the browser now downloads the php instead of running it.
I should note that any php running below the directory I changed works fine. But everything in that directory or subdirectory of that directory has this same problem with php files.
I have tried deleting the htaccess file in that directory, but that does not work, I get an internal error.
If I turn Override off, I get an internal error.
Something I changed is persisting in that directory and I'm wondering how to either
a. turn it off
b. add the correct handler to that htaccess file so that php files are run again (like they are on the rest of the server)
I did have the exact same issue so I deleted all the content of .htaccess and started trying only with handlers until I figured it out. My local .htaccess copy had the following SetHandler:
AddHandler x-httpd-php5-3 .php
In my case it worked after changing it to:
AddHandler application/x-httpd-php5 .php
It seems the whole trick is only the handler, I tried this solution in 2 different servers with different configurations and in both cases just changing AddHandler worked. If this doesn't work for you try a different handler for php.
Hope it helps.
Just realized I left this up unanswered after I solved the problem. If someone has a similar problem and is reading this : Check the permissions on all associated folders. I can't remember the specifics but one of the directories involved (I believe it was the htaccess directory) had permissions that persisted after changing some things and then changing them back.
I wanted to change the .php extension to .foo, to hide it for visitors.
My webserver has cPanel installed, so I logged in and clicked on "MIME Types", and entered the following:
MIME Type: application/x-httpd-php
Extension: foo
The problem is that it's not being parsed as PHP, but instead is downloaded (when you click the link, a file containing all the code of that file is being downloaded)
How would I solve this?
Add in httpd.conf or vhost.conf
<IfModule mime_module>
AddType application/x-httpd-php .foo
</IfModule>
But best way to solve you problem is in using mod_rewrite
If you have the necessary AllowOverride permissions to use .htaccess, try
AddHandler application/x-httpd-php5 .php .foo
For some reason our CentOS server needs x-httpd-php5, where as our WAMP internal server just uses x-httpd-php like you have (and -php5 will not work)
I have a CPanel based website and we used the above rule to set .html to be parsed as php, didn't even bother with the CPanel Mime settings... but there are other ways to determine if a server is running PHP so you're not really hiding that you use PHP from anyone who knows what they are doing
can't for the life of me work out why this isn't working - on a dreamhost server, I've created an htaccess file and added AddHandler php5-cgi .html .htm to allow php in html files, as per the dreamhost docs. On an identical dreamhost package, I've done the same thing for another site and it worked perfectly, but in this case it just won't parse the php! Is there anything I could have missed here which could be causing the problem? The htaccess is in the web root and isn't being overridden by anything else.
Try this
AddType application/x-httpd-php .html .htm
The above setting will work if the apache is picking php as a module.
AddHandler application/x-httpd-php .html .htm
or
AddHandler application/x-httpd-php5 .html .htm
above will work if apache is executing php as CGI?
there is no harm i would say to put both of the above conditions together but try one over other and see if it work for you.
read more here in this article I wrote.
Is your server using suPHP rather than mod_php or plain php-cgi?
Try using
AddHandler x-httpd-php .html .htm
or
AddType application/x-httpd-php .html .htm
instead.
Postscript
Shared Hosting services use UID based separation on individual accounts from each others. Most use suPHP, but some use suEXEC. They will use one of these. Both act as a su wrapper around php-cgi so you can't tell from the phpinfo()as its PHP scripting engine as this will report Server API CGI/FastCGI in both cases. For CGI initiated scripts, phpinfo doesn't report on the Apache config. You need either to look at your hosting provider's FAQ or possibly try:
<?php
header( "Content-Type: text/plain");
echo system('grep -iR LoadModule /etc/httpd /etc/apache2');
The hosting provider's support forums / FAQ might give specific configuration advice here. Have you tried them?
I've got the same problem as you but I just put this AddType php .html .htm to my .htaccess, it's working.
For me it is working for only like this:
AddHandler php-cgi .php .htm