Monday, April 27, 2009

Hide .php extension with url rewriting using .htaccess

Last time I’ve written an article about hiding php file extension where I’ve showed you how you can use .html or .asp extension of file instead of .php extension. But there was one flaw in that technique you have had to change the file extension explicitly but in this post I’m going to show you how to rewrite the URL instead of renaming the file extension Using this technique you will see product.html in the address bar of the browser but the actual file name remains product.php and you don’t need to rename the file extension. Furthermore you can rewrite the URL like product.php?id=5 to product-5.html.

what is the benefits of rewriting URL?

When a search engine visits the dynamic url like product.php?id=5 it does not give much importance to that URL as search engine sees “?” sign treat it as a url which keeps on changing. so we’re converting the dynamic URL like the product.php?id=5 to static url format like product-5.html. We’ll rewrite the url in such a way that in browser’s address bar it will display as a product-5.html but it actually calls the file product.php?id=5. So that why these kind of URL also named as SEO friendly URL.

what is required for URL rewriting ??

To rewrite the URL you must have the mod_rewrite module must be loaded in apache server. And furthermore, FollowSymLinks options also need to be enabled otherwise you may encounter 500 Internal Sever Error. If you don’t know much about mod_rewrite module then please check this post to know how to check and enable mod_rewrite module in apache?

Examples of url rewriting for seo friendly URL

For rewriting the URL, you should create a .htaccess file in the root folder of your web directory. And have to put the following codes as your requirement.

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\.htm$ $1.php [nc]

The following example will rewrite the test.php to test.html i.e when a URL like http://localhost/test.htm is called in address bar it calls the file test.php. As you can see the regular expression in first part of the RewriteRule command and $1 represents the first regular expression of the part of the RewriteRule and [nc] means not case sensitive.

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^product-([0-9]+)\.html$ products.php?id=$1

The following example will rewrite the product.php?id=5 to porduct-5.html i.e when a URL like http://localhost/product-5.html calls product.php?id=5 automatically.

How to check and enable mod_rewrite module in apache

Well there are lots of technique to check this but I’ll show you a very simple technique to check weather mod_rewrite module is enabled or not in you web server.

1) Type in a php file and save it and run that file in the server.
2) And now you can the list of information, just search the word “mod_rewrite” from the browser’s search menu
3) If it is found under the “Loaded Modules” section then this module is already loaded as you see in the picture below, otherwise you need to go to the next step for enabling mod_rewrite module.

check mod rewrite module

How to enable mod_rewrite module in apache in xampp, wamp?

Now, I’ll show you how to enable how to mod_rewrite module in apache installed under windows environment.
1) Find the “httpd.conf” file under the “conf” folder inside the Apache’s installation folder.
2) Find the following line “#LoadModule rewrite_module modules/mod_rewrite.so” in the “httpd.conf” file.You can do this easily by searching the keyword “mod_rewrite” from find menu.
3) Remove the “#” at the starting of the line, “#” represents that line is commented.
4) Now restart the apache server.
5) You can see now “mod_rewrite” in the Loaded Module section while doing “phpinfo()”.

How to check and enable mod_rewrite module in apache

Well there are lots of technique to check this but I’ll show you a very simple technique to check weather mod_rewrite module is enabled or not in you web server.

1) Type in a php file and save it and run that file in the server.
2) And now you can the list of information, just search the word “mod_rewrite” from the browser’s search menu
3) If it is found under the “Loaded Modules” section then this module is already loaded as you see in the picture below, otherwise you need to go to the next step for enabling mod_rewrite module.

check mod rewrite module

How to enable mod_rewrite module in apache in xampp, wamp?

Now, I’ll show you how to enable how to mod_rewrite module in apache installed under windows environment.
1) Find the “httpd.conf” file under the “conf” folder inside the Apache’s installation folder.
2) Find the following line “#LoadModule rewrite_module modules/mod_rewrite.so” in the “httpd.conf” file.You can do this easily by searching the keyword “mod_rewrite” from find menu.
3) Remove the “#” at the starting of the line, “#” represents that line is commented.
4) Now restart the apache server.
5) You can see now “mod_rewrite” in the Loaded Module section while doing “phpinfo()”.

Tuesday, April 7, 2009

ILIAS warning

if your pear is working, you also setup php.ini file
if you find error like this
Warning: file(/lang/setup_lang_sel_multi.lang) [function.file]: failed to open stream: No such file or directory in /www/htdocs/nrumble/ilias3/setup/classes/class.ilLanguage.php on line 108

Warning: file(/lang/setup_en.lang) [function.file]: failed to open stream: No such file or directory in /www/htdocs/nrumble/ilias3/setup/classes/class.ilLanguage.php on line 124

Warning: parse_ini_file(/setup/ilias.master.ini.php) [function.parse-ini-file]: failed to open stream: No such file or directory in /www/htdocs/nrumble/ilias3/setup/classes/class.ilSetup.php on line 144

Warning: parse_ini_file(/setup/client.master.ini.php) [function.parse-ini-file]: failed to open stream: No such file or directory in /www/htdocs/nrumble/ilias3/setup/classes/class.ilClient.php on line 73

Warning: dir(/lang) [function.dir]: failed to open dir: No such file or directory in /www/htdocs/nrumble/ilias3/setup/classes/class.ilLanguage.php on line 192

Warning: chdir() [function.chdir]: No such file or directory (errno 2) in /www/htdocs/nrumble/ilias3/setup/classes/class.ilLanguage.php on line 194

Fatal error: Call to a member function read() on a non-object in /www/htdocs/nrumble/ilias3/setup/classes/class.ilLanguage.php on line 197

Answer or this problem
// ADDED BY CDRIGA
define ("ILIAS_ABSOLUTE_PATH","/home/myusername/public_html/iliasfolder");

Wednesday, April 1, 2009

Installing PEAR on Godaddy shared accounts

I recently found out how to install PEAR on a Godaddy shared hosting account.
Visit http://pear.php.net/go-pear. Save the text displayed onto your desktop and name it go-pear.php. Upload this to your server. If you’re hosting multiple domains on the account, it’s best that you should upload this file in your root folder. Run this file on your browser and follow the on-screen instructions.
After completing the installation, it is time to edit your php.ini file. If you are running PHP4, there should be a file in the root directory called php.ini. If you are running PHP5, there should be a file in the root directory called php5.ini. If not, create one and add the following: include_path = “.:/usr/local/php5/lib/php:/home/content/s/a/m/sample/html/PEAR”. Keep in mind that /s/a/m/sample is just an example. Doing this will ensure that every page, you create, will look in the PEAR directory so that you it will use the installed packages.
This installation will include Pear_Frontend_Web which is the web-based admin interface. It may have created an index.php file in the directory where PEAR is installed (root). If not you can get a copy from PEAR/docs/PEAR_Frontend_Web/docs/index.php.txt. I would suggest creating a folder called pear_admin in the root directory and storing this file there. If you didn’t install PEAR in the root directory, you may need to edit this file accordingly.
You will need to create a .htaccess and .htpasswd file in the same directory as the index.php file. An example of how the .htaccess file should look as follows:AuthUserFile /home/content/s/a/m/sample/html/pear_admin/.htpasswdAuthType BasicAuthName “Web-based PEAR Frontend”Require valid-user
An example of how the .htpasswd file should look as follows:
admin:cGyUX9QugYMgE
This will create “admin” as the user name and “password” as the password. You can generate your own by going to this link - http://www.htaccesstools.com/htpasswd-generator/
Be aware that files beginning with a dot are invisible. You may have to edit your settings on the FTP app you’re using so that you can see them.
Once the files are created and saved, you can now go to http://your-domain.com/pear_admin/index.php. It will ask for the user name and password. Once you are logged in, you can now manage Pear via web browser. That’s it! Now you can run PEAR on a shared account from Godaddy. One less complaint
orignal link :http://abbyandwin.net/blog/2008/06/16/installing-pear-on-godaddy-shared-accounts/

Installing PEAR packages on WAMP

Well, after getting caught out recently with PEAR on a client installation, I thought it a good move to write a short tutorial for anyone who needs to install PEAR packages on their WAMP installation.
To start with, for the purposes of this blog, PEAR is a framework for implementing code libraries in PHP. In other words, it prevents you from having to re-invent the wheel - always a nice thing!
The WAMP installation installs PHP, and at the same time installs the basic PEAR framework. There is a directory called PEAR inside whatever folder contains PHP - on my particular installation the structure is php5.2.5\PEAR. Taking a peek inside the PEAR folder will reveal it populated with the basic framework for PEAR. Most of this you can ignore - I’m not going to detail installing this here - that seems to be well covered. I just couldn’t find out how to actually enabvle the damn packages when I started, so I hope this is useful!
Checking Configuration
This is THE place where things can go PEAR-shaped, if you’ll allow the pun. The PEAR folder must be included in the includes path within PHP.INI. Open PHP.INI and find the line that starts with :
include_path =
or, if commented out
; include_path =
You need to add the path to your PEAR folder to the end of this string. For example:
include_path = “.;e:\wamp\bin\php\php5.2.5\includes;e:\wamp\bin\php\php5.2.5\PEAR”
Now - it is CRUCIAL that there are NO spaces after or before the semi-colons that separate paths in this string. If there are, quite simply, PEAR will not work. Simple as that - any incldue path after such a space will NOT be searched by PHP.
Once you have modified the PHP.INI file, save it and restart your WAMP installation.
Installing a package
First of all, identify the package(s) that you want to install. To do this, take a look at http://pear.php.net/packages.php, which lists the available packages for PEAR. Identify the ones you’re interested in - for the same of example, let’s deal with a Mailer package.
Click on the relevant section of the Package list, and you’ll see a list of available Mail packages. Select the one of interest - choose the package ‘Mail’ and click on it. This will then display a page of details about the Mail package - and also the links to download, documentation, etc. Now, there are two ways to download stuff, depending upon whether you have access to the command line program for PEAR or not. This blog entry will assume you have - I’ll post the alternative instructions elsewhere.
To start with, make a note of the package name - ‘Mail’.
Check the Dependencies
Click on the ‘Download’ tab - you will see an entry someway down the page for ‘Dependencies’. These are PEAR packages that you need to install for your chosen package to work. Make a note of the dependencies - in this case, Net_SMTP. Now click on that dependency, and check it’s dependencies - do this and you will see Net_Socket and Auth_SASL listed. The latter is optional, so I won’t bother with that. There are two other packages listed - however they’re part of the PEAR framework.
So, we now have a list of packages to download and install. These are:
Mail, Net_SMTP, Net_Socket. (We’ll ignore the Auth_SASL one for this example).
Whilst you can automate the acquisition of dependencies, it’s educational to do it ‘the hard way’ at first. :) So that’s what we will do!
Start a Command Window
From your Windows Start menu, select the ‘Run’ entry, and enter ‘cmd.exe’. Now change directory to the PHP directory. On my machine this is:
E:\wamp\bin\php\php5.2.5
Once in there, type in pear list. This will list the currently installed pear packages. If it’s a new PEAR installation, there will be 3 packages listed 4 packages listed - PEAR, Archie_Tar, Console_Getopt and Structures_graph.
Now, type in pear update-channels. this connects to the PEAR repository - where the PEAR files live - and updates your local installation with data needed to get packages.
Now, type in:
pear download Mail
pear install Mail
The former command gets a ZIP file containing the Mail package from the PEAR repository, and the latter will install the mail package. Note the messages displayed on installation - the software warns you that you haven’t got the dependencies, and gives you a suggestion of a method of downloading the dependencies - which we’ll now use to get Net_SMTP an it’s dependencies.
We’ll also do this installation slightly different to the first one - thus showing there is more than one way to install a package. Type in:
pear install -a Net_SMTP
No download this time - this will go off and get Net_SMTP, and all of it’s dependencies, and install them - all in one fell swoop! The -a switch tells PEAR to get all the dependencies.
The files will be installed in to the PEAR folder. Sometiems a PHP file will be placed in the folder itself - as happens with the DB package. Other times a new folder will be created - like for Mail - and the PHP files placed in the new folder.
Testing the mailer.
Here is a piece of sample code to put in to a PHP file:require_once “Mail.php”;
$from = “Sender ”;
$to = “Recipient ”;
$subject = “Hi!”;
$body = “Hi,\n\nThis is a test!”;
$host = “mail.example.com”;
$username = “smtp_username”;
$password = “smtp_password”;
$headers = array (’From’ => $from,
’To’ => $to,
’Subject’ => $subject);
$smtp = Mail::factory(’smtp’,
array (’host’ => $host,
’auth’ => true,
’username’ => $username,
’password’ => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo(”

” . $mail->getMessage() . “

”);
} else {
echo(”

Message successfully sent!

”);
}
?>
Set up your own parameters for the mail server and the authentication required - username and password, and the address of the recipient - and if you have successfully installed PEAR Mail then you should get a mail sent. If you get any messages back refering to ‘No such file or directory’ then the chances are that the configuration of PHP.INI is a little screwed up. And there you have it!
orignal article : http://www.joep.communityhost.org.uk/?p=30