4

My local development PC is set up to use PHP5 by default, my client's host (1and1.co.uk) is set up to use PHP4 by default.

To enable PHP5 on a 1and1 account, you must add the following line to your .htaccess file:

AddType x-mapp-php5 .php

If I add this line to my local .htaccess file, it breaks my PHP.

How do I add this line conditionally based on the domain (or some other parameter?) so it is only executed by the live site and not my dev site?

I'd like to be able to just upload (FTP) my entire source tree without worrying about having to remember to edit the .htaccess on the server ever time.

e.g.

<IfDomain www.example.com>
    AddType x-mapp-php5 .php
</IfDomain>

... rest of .htaccess

Is this possible?

I don't have access to the server config file, only .htaccess

Thanks in advance.

4 Answers 4

3

To others looking at this, and using a local server with virtualhost directives: took me a while, and none of the methods found online worked (probably because my MAMP apache version is not 2.4 yet or something), but this one did.

Forget about adding 'conditional' lines to your .htaccess file: you can define which .htaccess file to use in your virtualhost setting!

So just create a file .htaccess_dev, and add this line to your virtualhost definition on your local / dev machine:

AccessFileName .htaccess_dev

So it becomes something like this:

<virtualhost>
ServerName www.example.local
DirectoryRoot /var/www/www.example.local
AccessFileName .htaccess_dev
</virtualhost>
0

Try this. I have no idea whether it'll work. The terminology used in the documentation suggests that it should, but since no one ever does what you're trying to do, it's a little up in the air.

<Location http://www.example.com/>
    AddType x-mapp-php5 .php
</Location>
1
  • Filled in a few more details so you have a better idea of what I am trying to achieve. Commented Jun 1, 2009 at 15:26
0

I know that you can do server-specific commands in httpd.conf using the VirtualHost tag. (http://httpd.apache.org/docs/1.3/vhosts/ip-based.html)

While I'm not 100% sure that you can use this in a .htaccess file, I would suggest trying the following:

<VirtualHost www.example.com>
    AddType x-mapp-php5 .php
</VirtualHost>
1
  • 1
    you can. see simultaneous post below. i'm a stackoverflow noob so not sure how to merge the two posts.
    – nategood
    Commented Jun 1, 2009 at 16:54
0

You can use the VirtualHost directive to accomplish this. I just did the same when I wanted django with mod_python to run only at a subdomain

<VirtualHost *:80>
DocumentRoot /www/docs/path
ServerName www.example.com
....

AddType x-mapp-php5 .php
</VirtualHost>

Not the answer you're looking for? Browse other questions tagged or ask your own question.