Posts filed under 'Apache'
PHP as Apache module
We can use php.ini directives configuration settings such as error_reporting, display_errors, auto_prepend_file etc from apache configuration files (httd.conf or .htaccess file).
Lets we want to append a config file (ex. init.php) at the beginning of a script(index.php). So we need to add the following statement in our .htaccess file.
1. init.php sample file
<?
define(”DOCUMENT_ROOT” , $_SERVER['DOCUMENT_ROOT']);
define(”DISPLAY_ERROR” , 1);
?>
2. index.php sample file
<?
print_r(DOCUMENT_ROOT);
?>
3..htaccess file
#php_value name value
#Can be used only with PHP_INI_ALL and PHP_INI_PERDIR type directives.
php_value auto_prepend_file init.php
N.B. All the files needs to should be store in the same directory as we use htaccess which used as per directory level. So all the php scripts in that directory will prepend the init.php file.
Now we are ready to test the script.
There are lots of php ini directives that can be altered from apache module.
For more info please visit the php manual
Cheer$
$haymoL
eXplOrinG PHP
Add comment December 18, 2007
URL Manipulation using mod_rewrite
What It is
mod_rewrite is frequently called the “Swiss Army Knife” of URL Manipulation. mod_rewrite is used for rewriting and redirecting URLs dynamically, using powerful pattern matching.
The most common use of mod_rewrite is to make ugly URL most attractive. For example , say our URL looks like http://www.example.com/index.php?cmd=login , and we want to show the url in the address bar as http://www.example.com/login. To do this we need to use the following.
# First make the RewriteEngine On
RewriteEngine On
# Translate login to /index.php?cmd=login
RewriteRule ^login$ /index.php?cmd=login [L]
Installing mod_rewrite
Because of its popularity, mod_rewrite is now included with all common Apache distributions. We can verify if your Apache installation has the mod_rewrite module by looking for a file named mod_rewrite.so under the modules folder in our Apache installation directory.
To make sure open up the httpd.conf file in the Apache conf folder and find the following
#LoadModule rewrite_module modules/mod_rewrite.so
The initail # means it commented out , so to install the mod_rewrite remove the # and restart the Apache. Thats all for mod_rewrite installation.
Testing mod_rewrite
We can write rules in httpd.conf file or in .htaccess file to work for per directory basis. .htaccess is used for customised rules for any specific directory.
Lets create .htaccess file in htdocs folder. and a index.php file that basically dump the POST variable.
index.php file goes as follows
// index.php file that basically do nothing only dump the post variable for this example
$cmd = $GET['login'];
if($cmd == ‘login’)
{
echo ” You are in login Page”;
}
else
{
echo “Elsewhere”;
}
# First make the RewriteEngine On
RewriteEngine On
# Translate login to /index.php?cmd=login
RewriteRule ^login$ /index.php?cmd=login [L]
Now test the above rule using the url : http://www.example.com/login and see the output.
For more info please visit : Apache Mod Rewrite Rule Doc
Add comment December 16, 2007




