Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何让php包含在html页面中运行?_Php_Html - Fatal编程技术网

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

如何让php包含在html页面中运行?,php,html,Php,Html,为了从一个.html文件执行php,我遵循了一个“如何”的解释,但我无法让它在我的.htaccess文件中工作。也许还有别的解决办法吗 这是我在.htaccess文件中的代码 AddType application/x-httpd-php .html 我目前没有在我的任何a href标记中建立.html,因为我没有在web地址栏中显示.html 当我尝试将上述代码放入.htaccess文件并导航到该站点时,浏览器提示我下载该页面,而不是导航到该页面。最后,我尝试在html页面上运行这个php包

为了从一个.html文件执行php,我遵循了一个“如何”的解释,但我无法让它在我的.htaccess文件中工作。也许还有别的解决办法吗

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

AddType application/x-httpd-php .html
我目前没有在我的任何a href标记中建立.html,因为我没有在web地址栏中显示.html

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

我的索引页中有以下链接代码:

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

看看这对你想做的事是否有效

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]

您可能需要更新服务器的httpdconf文件,以允许在扩展名为.html的文件中使用PHP。您的服务器可能不允许在.htaccess文件中使用该选项。为什么不将页面更新为
.php
扩展名,并将扩展名隐藏在.htaccess文件中?我一直在尝试这样做,这两种选择之一。但这也不起作用。我之前根据建议修改了.htaccess文件。我尝试了以下方法:在RewriteCond%{REQUEST_FILENAME}上重写引擎-d RewriteCond%{DOCUMENT_ROOT}/$1.php-f[NC]RewriteRule^(+.+)(?:.html)?$/$1.php[L,NC]您能不能更改文件的扩展名并更新链接?您可能想联系您的主机,询问他们是否允许在.html文件中执行PHP。这可能就是你的问题。我把文件改回了.php。我试图将原来的.html文件重定向到新的.php版本,但由于某些原因,重定向在我的htaccess文件中不起作用。然后我尝试在html中执行php代码,但这也不起作用。因此,我被两种方式困住了。Options+FollowSymLinks-multiviewsrewriteengine On RewriteBase/#hide file extension RewriteCond%{THE_REQUEST}^[A-Z]{3,}\s/+(.*)php[NC]RewriteRule^/%1[R=301,QSA,L]RewriteCond%{REQUEST\u FILENAME}-d RewriteCond%{DOCUMENT_ROOT}/$1\.php-f RewriteRule^([^/]+)/?$$1.php[L]#将旧的.html重定向到新的.php RewriteRule^submission-guidelines.html submission-guidelines.php[R=301,L]#您也可以这样做,并删除位置栏中的.php扩展名RewriteRule^submission-guidelines.php submission-guidelinets/[R=301,L]您是否已将
.htaccess
中的所有其他内容都去掉,只使用我提供的代码—只是为了看看它是否有效?这对我有用。
submission guidelines.html
submission guidelines.php
是否在根文件夹中?“它不起作用”是什么意思?
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]