0

I enabled PHP5 on my website and my webhost needs me to add the following to .htaccess files for PHP5 to work:

AddHandler application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml
AddType application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml

Locally, I am running XAMPP to develop code, but XAMPP does not want to work with the .htaccess file above.

I think it is an issue with XAMPP not recognizing php5 (but it does recognize php if I use "application/x-httpd-php" instead of "application/x-httpd-php5")

How do I resolve this?! I need the .htaccess files to look like above so they work with my webhost, but I need XAMPP to work locally with the same files without making changes!

4

3 回答 3

3

Apache有<IfDefine>指令。您可以使用它来隐藏AddType您自己的服务器:

<IfDefine !MyServer>
AddType application/x-httpd-php5 .php5 …
…
</IfDefine>

并启动apache

apachectl -D MyServer
于 2008-10-11T11:57:01.843 回答
0

So, you're in kind of a tough place; ideally speaking your webhost should not need you to put extra gunk in your htaccess files. Not knowing XAMPP too well, I can't offer a specific solution, but I can give you some pointers:

  1. Your webhost is running a custom compiled version of PHP that uses application/x-httpd-php5; while it is totally possible to build PHP yourself or find a custom build that has the SAPI layer configured appropriately, you probably don't want to do this.

  2. Depending on how much leeway your host is giving htaccess files, it may be possible to use <IfDefine> or <IfModule> to only conditionally execute the PHP fudge code. I haven't tested, and your webhost may have disabled this functionality. Also, you will have to find an appropriate conditional to test against.

  3. My favorite answer would be to suck it up, and maintain separate htaccess files. I do this on my website; I have a .htaccess.in file which contains "global" declarations, and an htaccess.php file which generates the real .htaccess file based on configuration, etc.

Hope that helps.

于 2008-10-11T05:36:04.047 回答
0

另一个简单的解决方案:在家里更改配置文件名。例如在 httpd.conf 中:

<Directory />
    #existing stuff here...
    AccessFileName .htaccess.home
</Directory>

现在您的家庭服务器将忽略您的“.htaccess”文件。您将使用“.htaccess.home”文件对其进行配置。

于 2009-03-28T04:56:07.953 回答