0

I followed a "how to" explanation in order to execute php from an .html file, but I cannot get it to work within my .htaccess file. Is there perhaps another solution?

This is the code that I have in my .htaccess file.

AddType application/x-httpd-php .html

I currently do not have .html established within any of my a href tags as I did not wont .html displaying within the web address bar.

When I tried placing the above code in my .htaccess file and navigating to the site, my browser prompted me to download the page instead of navigating to it. Ultimately, I am trying to run this php include function on my html page instead of a .php page.

I have this code within my index page for links:

<li class="home-btn" style="border-bottom:5px solid #ff9b2e;"><a href="/"><img src="images/home.svg" width="37px" alt="3Elements Review, a literary journal based in Chicago, Illinois." border="none" id="home-btn"></a></li>
<li class="current" style="background-color:#313131;"><a href="current-journal" class="current">CURRENT JOURNAL<span class="sub-nav">Our latest and greatest!</span></a></li>
<li class="submit" style="background-color:#404040;"><a href="submit" class="current">SUBMIT<span class="sub-nav">Your writing</span></a></li>
<li class="guidelines" style="background-color:#505050;"><a href="submission-guidelines" class="current">SUBMISSION GUIDELINES<span class="sub-nav">Everything you need to know is here</span></a></li>
<li class="blog" style="background-color:#4b4b4b;"><a href="http://3elementsreview.blogspot.com" class="current">BLOG<span class="sub-nav">Just a blog</span></a></li>
<li class="past" style="background-color:#404040;"><a href="past-journals" class="current">PAST JOURNALS<span class="sub-nav">Browse our issue archives</span></a></li>
<li class="about" style="background-color:#313131;"><a href="about-3elements" class="current">ABOUT 3E<span class="sub-nav">What we're about</span></a></li>

It appears this answer from another thread specific to godaddy works. Not even the accepted answer, but an additional comment.

Using .htaccess to make all .html pages to run as .php files?

Options +ExecCGI
AddType application/x-httpd-php .php .html
AddHandler x-httpd-php5 .php .html
Community
  • 1
  • 1
Marlon Fowler
  • 121
  • 3
  • 4
  • 15
  • 2
    You probably have to update the server's httpdconf file to allow PHP in files with a .html extension. Your server may not allow that in the .htaccess file. Why not update the pages to a `.php` extension and hide the extension in the .htaccess file? – timgavin Feb 24 '14 at 23:56
  • Ive been trying to do that, one of these two alternatives. But that didnt work either. I modified my .htaccess file earlier based upon recommendations. – Marlon Fowler Feb 25 '14 at 00:05
  • I tried this: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}/$1.php -f [NC] RewriteRule ^(.+?)(?:.html)?$ /$1.php [L,NC] – Marlon Fowler Feb 25 '14 at 00:06
  • Can you not just change the file's extensions and update your links? You may want to contact your host and ask them if they allow executing PHP in .html files. That could be your problem right there. – timgavin Feb 25 '14 at 00:09
  • I changed the file back to .php. I was trying to redirect the old .html file that I originally had the page as to the new .php version but for some reason the redirect would not work within my htaccess file. Then I tried executing php code within html and that doesnt work either. So I am stuck either way. – Marlon Fowler Feb 25 '14 at 00:13
  • How can I go about modifying the httpdconf file? – Marlon Fowler Feb 25 '14 at 00:13
  • You need admin access to the server in order to modify `httpdconf`. if you want to do a simple redirect just do `RewriteRule ^old_file.html new_file.php [L]` I've added an answer. See if that helps. – timgavin Feb 25 '14 at 00:17

1 Answers1

0

See if this works for what you're trying to do

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

# hide file extension
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.*)\.php [NC]
RewriteRule ^ /%1 [R=301,QSA,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule ^([^/]+)/?$ $1.php [L]

# redirect old .html to new .php
RewriteRule ^old_file.html new_file.php [R=301,L]

# you could also do this and remove the .php extension in the location bar
RewriteRule ^old_file.html new_file/ [R=301,L]
timgavin
  • 4,972
  • 4
  • 36
  • 48
  • Options +FollowSymLinks -MultiViews RewriteEngine On RewriteBase / # hide file extension RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(.*)\.php [NC] RewriteRule ^ /%1 [R=301,QSA,L] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{DOCUMENT_ROOT}/$1\.php -f RewriteRule ^([^/]+)/?$ $1.php [L] # redirect old .html to new .php RewriteRule ^submission-guidelines.html submission-guidelines.php [R=301,L] # you could also do this and remove the .php extension in the location bar RewriteRule ^submission-guidelines.php submission-guidelines/ [R=301,L] – Marlon Fowler Feb 25 '14 at 01:03
  • Did you get rid of *everything* else in your `.htaccess` and use *only* the code I provided - just to see if it works? This works for me. Are `submission-guidelines.html` and `submission-guidelines.php` in the root folder? What does "it didn't work" mean? – timgavin Feb 25 '14 at 01:47