Dubstaphone
Dubstaphone

Reputation: 420

php_value and php_flag throwing errors in .htaccess

I just moved web hosts, and I get errors in my .htaccess about php_flag and php_value not being defined. It worked fine on the other host.

This is what my .htaccess looks like:

php_value display_errors On
php_flag magic_quotes 1
php_flag magic_quotes_gpc 1
php_value mbstring.http_input auto
php_value date.timezone America/Los_Angeles

The whole thing:

php_value display_errors On
php_flag magic_quotes 1
php_flag magic_quotes_gpc 1
php_value mbstring.http_input auto
php_value date.timezone America/Los_Angeles
# Do not remove this line, otherwise mod_rewrite rules will stop working
RewriteBase /
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule ^(.*)$ $1\.php
DirectorySlash Off
# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]
# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]

Options -Indexes

What's going wrong here and how do I fix it?

Upvotes: 1

Views: 1931

Answers (1)

Ulrich Thomas Gabor
Ulrich Thomas Gabor

Reputation: 6654

Your new hoster is running PHP in CGI/FCGI/another SAPI mode. Setting PHP options like that in .htaccess files is only supported when PHP is run as apache module. Therefore the new server throws an internal error.

You can use htscanner PECL package for older PHP versions and the user.ini.files since PHP 5.3 (this is definitely preferred).

For the former htscanner solution wrap the php relevant lines inside of the .htaccess files in

<IfModule mod_php5.c>
  php_value ...
  php_flag ...
</IfModule>

For the latter new .user.ini solution create a file .user.ini in the root directory of your project, insert

display_errors=On
magic_quotes=On
magic_quotes_gpc=On
mbstring.http_input="auto"
date.timezone="America/Los_Angeles"

and remove the corresponding lines from the .htaccess file.

Security and deprecation

display_error setting to on in a production environment is not a good idea. magic_quotes is a deprecated feature for a long long time meanwhile. If you can, you should rewrite your scripts. If you are using a more recent version of PHP (like 5.4) this feature is not even available anymore.

Upvotes: 1

Related Questions