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

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...!!!:):)
chiropractor northern beaches Said,
Jun 21, 2014 @ 04:42

I am in the middle of working on a school report on this topic and your post has helped me with the information I needed to complete it. Thanks.
jason bond picks review Said,
Jun 22, 2014 @ 12:10

I researed valuable information on this point as I am working on a class project. Thank you posting useful information and its now becoming easier to accomplish this task.
fake watches Rolex Said,
Jun 26, 2014 @ 13:45

I like the way you described the topic with such clarity. This is something I have been thinking about for a long time and you really captured the essence of the subject.
outdoor furniture Said,
Jun 29, 2014 @ 08:06

I would like to thank you for your best written post, its informative and your writing style helped me to read it till end. Thanks man!
Rolex Watches for sale Said,
Jul 01, 2014 @ 08:56

Your article tells me you must have a lot of background in this topic. Can you direct me to other articles about this? I will recommend this article to my friends as well. Thanks
http://www.bestacnefacewash.co.uk/reviews/best-face-wash-for-spots-clearzine-pil Said,
Jul 01, 2014 @ 09:19

I have been reading in a class and we are looking at this subject in the next week. I will be assign my student to look at your post for good information.
hydrometer Said,
Jul 02, 2014 @ 09:30

I am preparing a research paper and collecting information on this topic. Your post is one of the better that I have read. Thank you for putting this information into one post.
Seevue Digital Said,
Jul 02, 2014 @ 12:17

Your site contains useful information on this topic as I am working on a school project. Thank you posting relative information and its now becoming easier to complete this topic.
hair loss dubai Said,
Jul 09, 2014 @ 09:29

I would like to thank you for your nicely written post, its informative and your writing style encouraged me to read it till end. Thanks
swords Said,
Jul 16, 2014 @ 09:20

I am writing a research paper and collecting information on this topic. Your post is one of the better that I have read. Thank you for putting this information into one location.
Accredited GED Diploma Said,
Aug 14, 2014 @ 06:03

Hi... Thank you for your excellent information. Your writing hand is very easy and everyone knows it simply.
Online Research Paper Writers Said,
Sep 04, 2014 @ 02:51

This type of information is well for the people who need to develop web pages for their projects.
jasa seo Said,
Sep 22, 2014 @ 08:11

You ended a few safe points near. I did a explore taking place the matter and establish a large amount individuals will exit the length of with with your blog.
Pesablog Said,
Oct 06, 2014 @ 09:05

How do i change the php.ini settings in Godaddy server?
DigitalOcean Promo Code Said,
Oct 10, 2014 @ 17:25

This is one of the nice article. its simply super. Doing a great job..
thesis writing services in uae Said,
Oct 31, 2014 @ 02:20

Thanks so much for this wonderful and great website as well as this post. This post is the kind of thing That keeps me on track through.
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