使用.htaccess将.html重定向到.php

使用.htaccess将.html重定向到.php,php,mod-rewrite,Php,Mod Rewrite,我有5个wordpress网站都使用相同的编码模板。该编码模板(我无法更改)调用了一个名为“2012.orange.html”的文件,其中包含一些基本的html布局代码。我在我的服务器的“/home/”目录中创建了一个“my_template.php”,在我的模板目录中创建了另一个“2012_orange.php”文件,该文件“包括来自“/home/”的“my_template.php” 我的目标是使用“/home/”目录中的“My_template.php”文件来控制5个不同站点的布局,但我不

我有5个wordpress网站都使用相同的编码模板。该编码模板(我无法更改)调用了一个名为“2012.orange.html”的文件,其中包含一些基本的html布局代码。我在我的服务器的“/home/”目录中创建了一个“my_template.php”,在我的模板目录中创建了另一个“2012_orange.php”文件,该文件“包括来自“/home/”的“my_template.php”

我的目标是使用“/home/”目录中的“My_template.php”文件来控制5个不同站点的布局,但我不知道如何让特定的.html文件调用.php

我使用以下代码对我的“robots.txt”做了类似的操作,效果很好:

# BEGIN - Robots Rewrite
RewriteEngine on
RewriteRule ^robots\.txt$ robots.php [L]
## END - Robots Rewrite
但我不能让它工作…我没有html布局:

# BEGIN - Template Rewrite
RewriteEngine on
RewriteRule ^2012\.orange\.html$ 2012_orange.php [L]
## END - Template Rewrite
同样,2012_orange.php将只包含以下内容:

<?php include ('/home/my_template.php'); ?>


在调用原始.html时,您知道如何让.htaccess重定向到文件的.php版本吗?

.htaccess仅用于HTTP请求重定向url。脚本运行后,.htaccess不会以任何方式包含模板,因为您包含的是文件,而不是URL。

能否从公用文件夹键入
2012\u orange.php
文件路径

对于根目录中的2012_orange.php,您的代码似乎运行良好

如果您在另一个文件夹中有
2012\u orange.php
文件,则必须更改路径,如
home/2012\u orange.php

# BEGIN - Template Rewrite
RewriteEngine on
RewriteRule ^2012\.orange\.html$ home/2012_orange.php [L]
## END - Template Rewrite