2013-10-16 71 views
5

我一直在试图让.HTML文件使用.htaccess文件处理.PHP文件,我已经使用了以下内容,它们都不起作用并试图访问测试页面给我一个选项来下载一个不存在的文件,有什么想法?处理HTML文件,如PHP

试过这两个;

AddType application/x-httpd-php .html .htm 

AddType application/x-httpd-php5 .html .htm 

这个想法是允许包括在我的网页,但仍然使用.HTML文件。

下面是我的.htaccess文件中的一些代码,我不认为它与addType相混淆,但是我会发布它。

## hide .html extension 
# To externally redirect /dir/foo.html to /dir/foo 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC] 
RewriteRule^%1 [R,L,NC] 

## To internally redirect /dir/foo to /dir/foo.html 
RewriteCond %{REQUEST_FILENAME}.html -f 
RewriteRule^%{REQUEST_URI}.html [L] 

1and1决定只允许我用下面的代码来完成它;

AddHandler x-mapp-php5 .html .htm 
+0

您需要添加'AddHandler应用程序/ x-httpd-php .html .htm' –

+0

这也帮助了我,因为某些原因主机LCN也决定很难并且只允许“AddHandler x-mapp-php5.html .htm ”。我会推荐我的客户离开! –

回答

3

您需要添加

AddHandler application/x-httpd-php .html .htm 
+0

不需要工作 – Switchfire

+0

@Switchfire不需要'.htaccess'就可以进行测试。很确定这是问题所在。这应该有效,我自己使用它。暂时删除'.htaccess'或将其禁用。 –

+0

@Switchfire同样尝试添加'AddHandler应用程序/ x-httpd-php5.html.htm',但我怀疑这会有所作为。 –

0

您还可以试试下面的代码。

AddHandler x-httpd-php .html .htm 

OR

AddType application/x-httpd-php .html .htm 
3

试试这个:

AddHandler application/x-httpd-php .html .htm 

AddHandler x-httpd-php .html .htm 

<FilesMatch "\.(htm|html|php)$"> 
SetHandler application/x-httpd-php 
</FilesMatch> 

<FilesMatch "\.(htm|html|php)$"> 
SetHandler application/x-httpd-php5 
</FilesMatch> 

编辑: 对于1 & 1服务器:

AddType x-mapp-php5 .html .htm 

其中一个应该工作

+0

不幸的是,这些都没有工作! – Switchfire

+0

@Switchfire和这个:AddHandler应用程序/ x-httpd-php5 .html .htm – Don

+0

你是否有必要的访问权限来在你的.htaccess文件中添加一个Handler? –