繁体   English   中英

如何获取php include以在html页面中运行?

[英]How can I get php include to function within an html page?

为了执行.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作品的话题看来的。 甚至没有接受的答案,而是一条附加评论。

使用.htaccess使所有.html页面作为.php文件运行?

Options +ExecCGI
AddType application/x-httpd-php .php .html
AddHandler x-httpd-php5 .php .html

看看这是否适合您想要做的事情

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]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM