如何让php包含在html页面中运行?

时间:2014-02-24 23:54:08

标签: php html

为了从.html文件执行php,我遵循了“如何”解释,但我无法在.htaccess文件中使用它。还有其他解决办法吗?

这是我在.htaccess文件中的代码。

AddType application/x-httpd-php .html

我目前没有在我的任何href标签中建立.html,因为我不会在网址栏中显示.html。

当我尝试将上述代码放入我的.htaccess文件并导航到该网站时,我的浏览器提示我下载该页面而不是导航到该页面。最终,我试图在我的html页面而不是.php页面上运行这个php include函数。

我在链接的索引页面中有这个代码:

<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>

看来这个答案来自另一个特定于godaddy的线程。甚至不是接受的答案,而是另外的评论。

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

1 个答案:

答案 0 :(得分:0)

看看这是否适用于你正在尝试做的事情

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]