web hosting reviews


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:
http://www.php.net/manual/en/ini.php#ini.list

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 3 >>

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?
Your comments on this article

(required)

(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

Back to Web Hosting Articles list

Web hosting companies A-Z:
All web hosting companies


About - Terms of Use - Privacy Policy -
Web Hosting Reviews