Archive

Archive for the ‘htaccess Solutions’ Category

How to Disable PHP Output Buffering With .htaccess

November 26th, 2010 No comments

In order to disable PHP outbut buffering for a single site, you can add the following line to .htaccess:

php_value output_buffering Off

Reboot Apache and have fun!

Categories: htaccess Solutions Tags:

How to Enable register_globals in php using .htaccess

January 28th, 2010 No comments

As you should already know, register_globals is a php.ini directive that manages the way PHP deals with variables. It has been deprecated for security issues and we won’t see it in PHP 6.0. If the deprecated register_globals directive is on (removed as of PHP 6.0.0), then variables_order also configures the order the ENV, GET, POST, COOKIE and SERVER variables are populated in global scope. So for example if variables_order is set to “EGPCS”, register_globals is enabled, and both $_GET['action'] and $_POST['action'] are set, then $action will contain the value of $_POST['action'] as P comes after G in our example directive value. This is extremely insecure and it is not recommended to enable this directive.

But if you really need it (for example, you need to transfer an old-made site to your server and make it working until all the variables are changed), you may enable it using an .htaccess file. This way register_globals will be active just for one site. Here is the string you need to add to your .htaccess file:

php_value register_globals 1

I wish you to change all the variables as soon as possible, but you may use my solution until then :)

How To Find The Version of Linux You Are Using

February 12th, 2009 No comments

Sometimes you need to know what version of the Operating system is installed on your server. This is extremely useful when you order a dedicated server and want to know what is the version of OS on it. A simple command will help you as usual:

cat `ls /etc/*{-,_}{release,version} 2>/dev/null | head -n 1`

This will show you something like

The picture below shows the difference between common commands: one shown above and uname -a. Sometimes you don’t need the kernel version, just the operating system name. This command should help you to do that.

htaccess Site Redirection Without Parameters

September 1st, 2008 1 comment

Sometimes you need to redirect all traffic from one site to another. Very often site structure is different and the need is to send visitors to the main page of the site. This makes Site Redirection tabs of all known panels unusable, as the parameters are being sent to the new site. For example, if you had www.oldsite.com/index.php?f=9 and you’ve set redirection to www.newsite.com/, you will be redirected to www.newsite.com/index.php?f=9.

Sometimes you can omit these parameters (for example, when pointing to a PHP script with at least one parameter), but most probably you won’t need this. How to hide these parameters and send your users to the main page of a new site? Here is an .htaccess solution.

We will need two files: .htaccess in the root directory of your site and a PHP file located anywhere you like. First of all we need to create an .htaccess file:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://www.site.com/redirect.php

What does this piece of code do? It redirects all requests to the server (^(.*)$) to a PHP file, that processes redirection. All the unnecessary parameters will be sent to this PHP file and it won’t transmit them further as it contains only one string:

<?
header (“Location: http://newsite.com”);
?>

Can you see the difference? None of old site parameters are sent to the new site, everything looks clear and simple.

I think there is a smarter solution for this, I would encourage you to post it here.