Ratings, reviews, plans and features to help you find the right web hosting provider for your site.

Change PHP variables using .htaccess

Web Hosting Articles » A simple guide to .htaccess » Change PHP variables using .htaccess

If you need to change the way your PHP is working you can do that using .htaccess.
Please, note that not all PHP options can be changed using .htaccess.
A list of options that can be changed using .htaccess file can be found at:

The ones that can be changed with .htaccess are the ones marked with: PHP_INI_PERDIR or PHP_INI_ALL. The ones marked as PHP_INI_SYSTEM cannot be changed via .htaccess files.

The syntax is pretty simple:

php_flag [variable_name] [value]

For example if you need to turn off register_globals:

php_flag register_globals off

If you need to change the PHP include path:

php_value include_path ".:/usr/local/lib/php:/your_include/path"

The include_path string starts with a dot “.” And then each additional path is separated with a semi colon.   (e.g. .:/path1:/path2:/path3)

  1. How to block users from accessing your site based on their IP address
  2. How to prevent or allow directory listing?
  3. How to change the error documents – 404 Page Not Found, etc
  4. Using .htaccess for password protecting your folders
  5. Using .htaccess to block referrer spam
  6. Disable Hot-Linking of images and other files
  7. Redirect URLs using .htaccess
  8. Introduction to mod_rewrite and some basic examples
  9. Force SSL/https using .htaccess and mod_rewrite
  10. 301 Permanent redirects for parked domain names
  11. Enable CGI, SSI with .htaccess
  12. How to add Mime-Types using .htaccess
  13. Change default directory page
  14. Block Bad robots, spiders, crawlers and harvesters
  15. Make PHP to work in your HTML files with .htacess
  16. Change PHP variables using .htaccess
  17. HTTP Authentication with PHP running as CGI/SuExec
  18. Force www vs non-www to avoid duplicate content on Google
  19. Duplicate content fix index.html vs / (slash only)

Comments 9 >>

Vindexus Said,
Jan 21, 2007 @ 06:11

Where do I put the file? Where do I call the file from? Is it automatically called?
vince Said,
Jan 21, 2007 @ 16:43

You need to place the file in the folder where you need it to have the settings applied.

In general you can place the file in your website main folder as .htaccess files act recursively.
Mike Said,
Jun 14, 2007 @ 21:24

I am using you example to test the .htaccess configuration, but when I put the parameter (and it is the only one), the server response:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@mtxsoftware.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

It is necesary start a PHP block or something in the file?
Faltzer Said,
Aug 16, 2009 @ 13:46

You receive an internal server error on some hosts because they disallow php_value and php_flag changes in .htaccess files, despite the syntax being perfectly valid.

You should just research which host you make your allegiance to and stick with it to ensure that they support what you need. Granted, HostGator allows you to configure PHP values, as they give you a custom php.ini file for you to adjust whatever you need as far as parsing scripts goes for PHP.
Shuaib Nawaz Said,
Nov 02, 2009 @ 15:41

Normally php_value include_path "path" over rides the existing path configuration that is defined in php.ini. What I need to do if I want to extend include_path by appending new paths.
Vince Said,
Nov 02, 2009 @ 20:46

@Shuiab Nawaz

You will not be able to do this using a php.ini or an .htaccess file.

You will have to handle this within your PHP coding. For example:

Deepika Pawar Said,
Mar 01, 2010 @ 01:33

It will be more easy to add php handler in .htaccess file. For example:
To switch to PHP 4.4:

AddHandler application/x-httpd-php4 .php .php4 .php3
Bobby Said,
Apr 03, 2011 @ 08:42

i have this website going and my server refused the creation of a virtual directory and on checking the PHP default settings, the virtual directory support is not enabled.

what can i do to enable this and how can i set up the php settings to accept prestashop CMS.

for now i am using free web hosting domain with eu5.org
freelancing php coder Said,
Jul 11, 2011 @ 05:35

This is one of the nice article. its simply super. Doing a great job..

Simply super your explanation:):)

Thanks a lot...!!!:):)
Your comments on this article


(required but never displayed)

security code

Previous: Make PHP to work in your HTML files with .htacess Next: HTTP Authentication with PHP running as CGI/SuExec