tags:

views:

1013

answers:

4

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!

A: 

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.

Edward Z. Yang
+2  A: 

Apache has <IfDefine> directive. You can use it to hide AddType from your own server:

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

And start apache with

apachectl -D MyServer
porneL
A: 

"IfDefine" worked. Thanks!

You should award him for the best answer then.
Till
A: 

Another simple solution: change the config file name at home. E.g. in httpd.conf:

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

Now your home server will ignore your ".htaccess" files. You'll configure it with ".htaccess.home" files.

mrclay