Solved

Adding a handler to htaccess

Posted on 2014-07-21
15
209 Views
Last Modified: 2014-07-22
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
Comment
Question by:ddantes
  • 8
  • 7
15 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 40210220
Just this is all you need

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

Author Comment

by:ddantes
ID: 40210260
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
 
LVL 58

Expert Comment

by:Gary
ID: 40210271
Then try replacing
AddType application/x-httpd-php .html .htm

with

AddHandler x-httpd-php .html .htm
0
 
LVL 58

Expert Comment

by:Gary
ID: 40210281
Who is your host?
0
 

Author Comment

by:ddantes
ID: 40210313
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
 
LVL 58

Expert Comment

by:Gary
ID: 40210326
Change <?PHP to lowercase - <?php
I don't know if this may be the problem - never come across a scenario where it mattered
0
 

Author Comment

by:ddantes
ID: 40210336
Well, you have now encountered that scenario.  However, it only works on the virtual server, not on the remote server.
0
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
LVL 58

Expert Comment

by:Gary
ID: 40210347
: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
 

Author Comment

by:ddantes
ID: 40210367
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
 
LVL 58

Accepted Solution

by:
Gary earned 250 total points
ID: 40210370
If none of them work then your host has some hooky setup.
0
 

Author Comment

by:ddantes
ID: 40210382
The host is in Europe, sleeping now.  I'll post again after I hear from him tonight or tomorrow.  Thanks.
0
 

Author Comment

by:ddantes
ID: 40210464
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
 
LVL 58

Expert Comment

by:Gary
ID: 40210485
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
 

Author Comment

by:ddantes
ID: 40210515
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
 

Author Comment

by:ddantes
ID: 40212270
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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

Suggested Solutions

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now