• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 230
  • Last Modified:

Adding a handler to htaccess

I have added some php code to certain htm and html files on my server, and I don't want to change their extension to php.  So I added this code to my .htaccess:

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

To test this, I uploaded www.mauitradewinds.com/test.htm, containing  this code:

<?PHP
echo "PHP is working.";
?>
...but when I load that page, it is blank.  Please advise.
0
ddantes
Asked:
ddantes
  • 8
  • 7
1 Solution
 
GaryCommented:
Just this is all you need

AddType application/x-httpd-php .html .htm
0
 
ddantesAuthor Commented:
There must be something I'm missing, so I posted the entire .htaccess as a snippet.  The handler is the last part.  The test.htm file, containing php code, loads as a blank page in my browser.

RewriteEngine On
RewriteBase /

# replace double slashes in URL with single slash
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/{2,} [NC]
RewriteRule ^(.*) $1 [R=301,L]

# redirect index.htm to the root domain
RewriteRule ^index\.htm$ / [NC,R=301,L]

# redirect entire site from non-www to www except Panoramic View pages
RewriteCond %{REQUEST_URI} !^/viewtriage.htm$
RewriteCond %{REQUEST_URI} !^/view.htm$
RewriteCond %{REQUEST_URI} !^/viewipad.htm$
RewriteCond %{REQUEST_URI} !^/viewother.htm$
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

# redirect view.htm to non-www if it initially has a www prefix
RewriteCond %{HTTP_HOST} www\. [NC]
RewriteRule /?(view\.htm) http://mauitradewinds.com/$1 [NC,L,R] 

# redirect erroneous RezEasy page requests to proper path
Options +FollowSymlinks
RewriteEngine on
RedirectMatch 301 /RezEasy/RezEasy/(.*) /RezEasy/$1
RedirectMatch 301 /RezEasy/css(.*) /css/$1
RedirectMatch 301 /RezEasy/brochures(.*) /brochures/$1
RedirectMatch 301 /RezEasy/js(.*) /js/$1
RedirectMatch 301 /RezEasy/RSS(.*) /RSS/$1
RedirectMatch 301 /RezEasy/SpryAssets(.*) /SpryAssets/$1
RedirectMatch 301 /RezEasy/Rotator(.*) /Rotator/$1
RedirectMatch 301 /RezEasy/Maui-Beaches(.*) /Maui-Beaches/$1
RewriteRule ^RezEasy/bf0001.html(.*)$ http://mauitradewinds.com/RezEasy/0001/bf0001.html$1 [r=301,nc]
RewriteRule ^RezEasy/av0001.html(.*)$ http://mauitradewinds.com/RezEasy/0001/av0001.html$1 [r=301,nc]
RewriteRule ^RezEasy/cl0001.html(.*)$ http://mauitradewinds.com/RezEasy/0001/cl0001.html$1 [r=301,nc]
RewriteRule ^RezEasy/cf0001.html(.*)$ http://mauitradewinds.com/RezEasy/0001/cf0001.html$1 [r=301,nc]
RewriteRule ^RezEasy/nr0001.html(.*)$ http://mauitradewinds.com/RezEasy/0001/nr0001.html$1 [r=301,nc]

# redirect requests for obsolete root suffixes to root domain, omitting "nc" so it is case sensitive
Options +FollowSymlinks
RewriteEngine on
Rewriterule ^BBL(.*)$ http://www.mauitradewinds.com$1 [r=301]
Rewriterule ^BNB(.*)$ http://www.mauitradewinds.com$1 [r=301]
Rewriterule ^GoH(.*)$ http://www.mauitradewinds.com$1 [r=301]
Rewriterule ^Google(.*)$ http://www.mauitradewinds.com$1 [r=301]
Rewriterule ^GR(.*)$ http://www.mauitradewinds.com$1 [r=301]
Rewriterule ^HC(.*)$ http://www.mauitradewinds.com$1 [r=301]
Rewriterule ^HVEL(.*)$ http://www.mauitradewinds.com$1 [r=301]
Rewriterule ^MAG(.*)$ http://www.mauitradewinds.com$1 [r=301]
Rewriterule ^MWA(.*)$ http://www.mauitradewinds.com$1 [r=301]
Rewriterule ^MWN(.*)$ http://www.mauitradewinds.com$1 [r=301]
Rewriterule ^TK(.*)$ http://www.mauitradewinds.com$1 [r=301]
Rewriterule ^VM(.*)$ http://www.mauitradewinds.com$1 [r=301]
Rewriterule ^VRBO(.*)$ http://www.mauitradewinds.com$1 [r=301]
Rewriterule ^Best(.*)$ http://www.mauitradewinds.com$1 [r=301,NC]


# redirect requests for obsolete .shtml suffixes to corresponding .htm page
RewriteEngine on
RewriteRule ^(.*)\.shtml$ $1.htm


# redirect failed page requests the customized 404.htm page
ErrorDocument 404 /404.htm
Rewriterule ^404.html(.*)$ http://www.mauitradewinds.com/404.htm$1 [r=301,nc]
 

# Redirect visitors with MSIE <IE9 to pages which don't rely on HTML5
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "MSIE [6-8]" [NC]
RewriteRule ^index\.htm$ http://www.mauitradewinds.com/IE8index.php [L]
RewriteRule  ^/$ http://www.mauitradewinds.com/IE8index.htm [L]
RewriteCond %{HTTP_USER_AGENT} "MSIE [6-8]" [NC]
RewriteRule ^suite.htm(.*)$ http://www.mauitradewinds.com/IE8suite.php$1 [L]
RewriteCond %{HTTP_USER_AGENT} "MSIE [6-8]" [NC]
RewriteRule ^StarWind.htm(.*)$ http://www.mauitradewinds.com/IE8StarWind.php$1 [L]
</IfModule>


# Redirect mobile/tablet visitors to the respective dedicated mobile page
RewriteEngine On
# Check for mime types commonly accepted by mobile devices
RewriteCond %{HTTP:x-wap-profile} !^$ [OR]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC,OR]
RewriteCond %{HTTP:Profile} !^$
RewriteCond %{REQUEST_URI} ^/$
RewriteRule ^ http://www.mauitradewinds.com/m_index.php$1 [r=301,nc] 
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^suite.htm(.*)$ http://www.mauitradewinds.com/m_suite.php$1 [L]
RewriteCond %{HTTP_USER_AGENT} "android|blackberry|ipad|iphone|ipod|iemobile|opera mobile|palmos|webos|googlebot-mobile" [NC]
RewriteRule ^StarWind.htm(.*)$ http://www.mauitradewinds.com/m_StarWind.php$1 [L]

# Block specified IP addresses because visitors abused the contact form
order allow,deny
deny from 188.143.232.211
deny from 61.50.245.133
deny from 184.116.118.46
allow from all

# Parse htm and html pages as php, allowing php code to run on those files
AddType application/x-httpd-php .html .htm 

Open in new window

0
 
GaryCommented:
Then try replacing
AddType application/x-httpd-php .html .htm

with

AddHandler x-httpd-php .html .htm
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
GaryCommented:
Who is your host?
0
 
ddantesAuthor Commented:
I changed the .htaccess code, but no improvement.  Maybe my test code is faulty?

<?PHP
echo "PHP is working.";
?>

If I add the handler code to the Apache httpd.conf, I even get a blank page when I load that file in a virtual server.

Here is a link to my host's Apache info, if that helps...
http://www.mauitradewinds.com/PHP-info.php
0
 
GaryCommented:
Change <?PHP to lowercase - <?php
I don't know if this may be the problem - never come across a scenario where it mattered
0
 
ddantesAuthor Commented:
Well, you have now encountered that scenario.  However, it only works on the virtual server, not on the remote server.
0
 
GaryCommented:
:o)
It can depend on the host the exact format - be easier to just direct you here for every possible combination
http://www.velvetblues.com/web-development-blog/how-to-parse-html-files-as-php/
0
 
ddantesAuthor Commented:
Wow, what a chore!  I tried all the options in that article, and none of them work.  My web host is a small, private company. I'll ask the host about it and then post again.
0
 
GaryCommented:
If none of them work then your host has some hooky setup.
0
 
ddantesAuthor Commented:
The host is in Europe, sleeping now.  I'll post again after I hear from him tonight or tomorrow.  Thanks.
0
 
ddantesAuthor Commented:
Gary:  Just checking -- is there some code which must preface the line with AddHandler?  Something which loads or invokes an over-ride module?  Because I just have that line by itself in .htaccess
0
 
GaryCommented:
No, just double checked on my own install and it's just the one line
Haven't got time to go through your htaccess now but move it to the beginning of the file.
0
 
ddantesAuthor Commented:
I made an .htaccess file with just that one line, uploaded it, and it didn't work.  I'll wait to see what the web host says, and post again.
0
 
ddantesAuthor Commented:
My web host edited the code to get it working.  This is what it required...
AddType x-httpd-php5 .html .htm
AddHandler php5-fastcgi .html .htm

Thank you for your help!
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now