2012-12-23 60 views
0

我有5個使用相同編碼模板的WordPress站點。該編碼模板(我無法更改)使用一些基本的html佈局代碼調用名爲「2012.orange.html」的文件。我在我的服務器的「/ home /」目錄中創建了一個「my_template.php」,而在我的模板目錄中的另一個「2012_orange.php」文件中,「/ home /」包含了「my_template.php」。使用.htaccess將.html重定向到.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版本?

回答

1

.htaccess僅在HTTP請求中用於重定向url。腳本運行後,包括模板不會被.htaccess以任何方式包含,因爲您包含的是文件,而不是網址。

1

你能從公用文件夾中輸入2012_orange.php文件路徑嗎?

你的代碼看起來,如果你有2012_orange.php文件的另一個文件夾裏面做工精細的根目錄2012_orange.php,

你必須改變像home/2012_orange.php

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