Current time: 11-26-2024, 03:29 AM Hello There, Guest! (LoginRegister)


Post Reply 
problem parsing html as php with .htaccess
Author Message
HarryPW Offline


Posts: 2
Joined: Jan 2009
Reputation: 0
Post: #1
problem parsing html as php with .htaccess
I'm using a CMS witch save all the files as a .html document
Normally I put a .htaccess file in the root with:

AddType application/x-httpd-php .php .htm .html
or
AddHandler php-fastcgi .html

and use my own error404 document from the CMS with:
ErrorDocument 404 /error404.html

but this all doesn't work under ispCP.

Anyone a suggestion or a solution

Thanx
Harry
(This post was last modified: 01-14-2009 08:47 PM by HarryPW.)
01-14-2009 08:16 PM
Find all posts by this user Quote this message in a reply
BeNe Offline
Moderator
*****
Moderators

Posts: 5,899
Joined: Jan 2007
Reputation: 68
Post: #2
RE: problem parsing html as php with .htaccess
Quote:Anyone a suggestion or a solution
Any Apache (Error) Logs ?

Greez BeNe
01-14-2009 08:50 PM
Visit this user's website Find all posts by this user Quote this message in a reply
HarryPW Offline


Posts: 2
Joined: Jan 2009
Reputation: 0
Post: #3
RE: problem parsing html as php with .htaccess
No errors today in the Apache log concerning php or htaccess (only about ispCP and Horde)

This is the .htaccess file I want to use
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
ErrorDocument 404 /error404.html

I also changed
AddType application/x-httpd-php .php .htm .html
into
AddHandler php-fastcgi .html

still didn't work.
It looks like a .htaccess file can't be used in the domainroot.

WR
Harry
01-14-2009 09:18 PM
Find all posts by this user Quote this message in a reply
jdubs11 Offline


Posts: 4
Joined: Jan 2010
Reputation: 0
Post: #4
RE: problem parsing html as php with .htaccess
(01-14-2009 09:18 PM)HarryPW Wrote:  No errors today in the Apache log concerning php or htaccess (only about ispCP and Horde)

This is the .htaccess file I want to use
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html
ErrorDocument 404 /error404.html

I also changed
AddType application/x-httpd-php .php .htm .html
into
AddHandler php-fastcgi .html

still didn't work.
It looks like a .htaccess file can't be used in the domainroot.

WR
Harry

Is there a resolution to this? The company that I lease my server from just recently upgraded to ispCP and now I cannot render any .html files as PHP. They indicated that a change would need to be made to php.ini since the .htaccess method I had been using would no longer work since PHP was no longer being run as a module. When asked what needed to be updated in php.ini, they responded w/ an 'I don't know, try adding AddHandler php-fastcgi .html to .htaccess'. This did not work for me either. Please help.
01-20-2010 11:44 PM
Find all posts by this user Quote this message in a reply
kilburn Offline
Development Team
*****
Dev Team

Posts: 2,182
Joined: Feb 2007
Reputation: 34
Post: #5
RE: problem parsing html as php with .htaccess
First of all, you have to determine if your server is using FastCGI or Fcgid, because the configurations differ between them.

Under fastcgi
As long as .htacces is allowed to override FileInfo settings (AllowOverride +FileInfo or AllowOverride All), you can force files with .ext1 [.ext2 [...]] extensions to be run as a php script with:
Code:
# Enable php for another extension
AddHandler php-fastcgi .ext1 .ext2

Similarly, you can...
Code:
# Disable php in this folder and it's childs (unles re-enabled by another .htaccess)
RemoveHandler .php .php5

Under fcgid
You're out of luck, as the default configuration doesn't allow you to do this (at least I've been unable to). Now, I enabled this possibility by following these steps:

1. Replace the "<IfModule mod_fcgid.c>....</IfModule>" block from the files /etc/ispcp/apache2/parts/{als,dmn,sub}_php2_entry.tpl by the following one:
Code:
<IfModule mod_fcgid.c>
        Alias /fcgi/ {STARTER_DIR}/{DMN_NAME}/
        <Directory "{STARTER_DIR}/{DMN_NAME}/">
                AllowOverride None
                SetHandler fcgid-script
                Options +ExecCGI
        </Directory>
        AddHandler php{PHP_VERSION}-script .php .php{PHP_VERSION}
        Action php{PHP_VERSION}-script /fcgi/php{PHP_VERSION}-fcgi-starter
        AddType application/x-httpd-php .php
    </IfModule>

2. Regenerate domain configurations and restart apache.

3. Insert the following in your .htaccess:
Code:
# Enable php for html-files
AddHandler php5-script .htm .html

Similarly, you can...
Code:
# Disable php in this folder and it's childs (unles re-enabled by another .htaccess)
RemoveHandler .php .php5

Using mod_rewrite
Obviously, you can also try to use mod_rewrite instead:
Code:
RewriteEngine On
RewriteRule ^(.*).html?$ $1.php [L]

And then rename all your files to .php instead of .htm(l)...

Hope this helped.
(This post was last modified: 01-21-2010 02:44 AM by kilburn.)
01-21-2010 02:36 AM
Visit this user's website Find all posts by this user Quote this message in a reply
jdubs11 Offline


Posts: 4
Joined: Jan 2010
Reputation: 0
Post: #6
RE: problem parsing html as php with .htaccess
(01-21-2010 02:36 AM)kilburn Wrote:  Under fcgid
You're out of luck, as the default configuration doesn't allow you to do this (at least I've been unable to). Now, I enabled this possibility by following these steps:

1. Replace the "<IfModule mod_fcgid.c>....</IfModule>" block from the files /etc/ispcp/apache2/parts/{als,dmn,sub}_php2_entry.tpl by the following one:
Code:
<IfModule mod_fcgid.c>
        Alias /fcgi/ {STARTER_DIR}/{DMN_NAME}/
        <Directory "{STARTER_DIR}/{DMN_NAME}/">
                AllowOverride None
                SetHandler fcgid-script
                Options +ExecCGI
        </Directory>
        AddHandler php{PHP_VERSION}-script .php .php{PHP_VERSION}
        Action php{PHP_VERSION}-script /fcgi/php{PHP_VERSION}-fcgi-starter
        AddType application/x-httpd-php .php
    </IfModule>

Ok, it appears I have been setup w/ fcgi. To confirm what you're saying, the block in the xyx_php2_entry.tpl files looks like this currently
Code:
<IfModule mod_fcgid.c>
    Include {MODS_DIR}/fcgid_ispcp.conf
        <Directory {WWW_DIR}/{DMN_NAME}/htdocs>
            FCGIWrapper {STARTER_DIR}/{DMN_NAME}/php{PHP_VERSION}-fcgi-starter .php
            Options +ExecCGI
        </Directory>
        <Directory "{STARTER_DIR}/{DMN_NAME}">
            AllowOverride None
            Options +ExecCGI MultiViews -Indexes
            Order allow,deny
            Allow from all
        </Directory>
    </IfModule>

All of that should be replaced w/ what you indicated above?
(This post was last modified: 01-21-2010 03:05 AM by jdubs11.)
01-21-2010 03:04 AM
Find all posts by this user Quote this message in a reply
kilburn Offline
Development Team
*****
Dev Team

Posts: 2,182
Joined: Feb 2007
Reputation: 34
Post: #7
RE: problem parsing html as php with .htaccess
Right, the whole block should be replaced Smile
01-21-2010 03:39 AM
Visit this user's website Find all posts by this user Quote this message in a reply
jdubs11 Offline


Posts: 4
Joined: Jan 2010
Reputation: 0
Post: #8
RE: problem parsing html as php with .htaccess
(01-21-2010 03:39 AM)kilburn Wrote:  Right, the whole block should be replaced Smile

you rock. only thing I noticed now is that I have to sniff the page in order for it to start compiling, is there a work around for this? really not a big deal as its now working and there aren't too many pages to do this for but wanted to check before going down that road.

thanks again!
01-21-2010 04:17 AM
Find all posts by this user Quote this message in a reply
kilburn Offline
Development Team
*****
Dev Team

Posts: 2,182
Joined: Feb 2007
Reputation: 34
Post: #9
RE: problem parsing html as php with .htaccess
Sorry but I don't understand you... what do you mean by "sniff the page"? ... and what's this compiling stuff (php is interpreted, as you surely know)?
01-21-2010 04:43 AM
Visit this user's website Find all posts by this user Quote this message in a reply
jdubs11 Offline


Posts: 4
Joined: Jan 2010
Reputation: 0
Post: #10
RE: problem parsing html as php with .htaccess
(01-21-2010 04:43 AM)kilburn Wrote:  Sorry but I don't understand you... what do you mean by "sniff the page"? ... and what's this compiling stuff (php is interpreted, as you surely know)?

sorry, compiling was a bad choice of words (java developer by day). pages were not rendering php until I made an update to them (just deleted a space for instance). Is this just a caching issue w/ fcgi? either way, I think I can just use touch to update the timestamp.

thanks again for your help.
01-21-2010 04:49 AM
Find all posts by this user Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)