So you have decided to develop your own website and
here I come to give you some rock solid advices which can do wonders
for you. Before that I assumed that you are going to build your website
on Linux-Apache-MySQL. Here you must know some basic working guidelines
of Apache and PHP. The configuration of Apache web server is decided by
a file called httpd.conf and all apache settings are written there. But
apache allows you to modify these settings and you can easily override
your apache settings to make it suitable for your purpose. Similarly,
PHP settings are written in php.ini file and you can overwrite that
too. To overwrite apache settings you need to place a file named
.htaccess in your web folder. This htaccess file can overwrite
httpd.conf settings. An htaccess file overwrites settings from down to
top approach. That is htaccess file placed under
/var/home/sites/includes can overwrite the htaccess file in
/var/home/sites/.
Trapping Error: There are five kinds of errors that one website can experience. These are
1.
400 Error (Bad Request): It means that a request for a URL has been
made but the server is not configured or capable of responding to it.
2. 401 Error (Unauthorized Access): It means that a request for a URL
is generated but the request failed to authorize itself as per security
settings.
3. 403 Error (Forbidden Error): If any URL has been made for non-access
and the request tries to access it, this error is generated.
4. 404 Error (Page Not Found): If any request for URL comes to the server which is not available then this error is generated.
5. 500 Error (Internal Server Error): For any internal error the server throws this error message to browser.
The
wonder is that by adding a few lines you can get past the error message
and can show your own custom error message. For this develop 5 html
pages which will be shown in case these errors are generated. And then
add these lines to it.
ErrorDocument 400 /400-page.html
ErrorDocument 401 /401-page.html
ErrorDocument 403 /403-page.html
ErrorDocument 404 /404-page.html
ErrorDocument 500 /500-page.html
Mod_Rewrite
(Your own friendly URL): Say you have a php page and the url for this
is http://www.yourwebsite.com/product.php?p =cell_phone . Now
?p=cell_phone is the query string and the requested product.php page
gets the value and fetches data from database using php script using
the parameter. This kind of URL is not indexed by google properly.
Dont worry, you can customize very easily using htaccess file. Add the
following line in htaccess file and rename the link as
cell_phone_product.html.
RewriteEngine on
Options FollowSymLinks
RewriteRule (A-Za-z0-9:blank:_:digit:.-)._product.html product.php?p=1 L
Now
the first part (A-Za-z0-9:blank:_:digit:.-) finds any name that
comes before product and store it in the variable 1. It then
internally redirects it to the products.php by making the desired URL.
So in browser cell_phone_product.html appears where internally
product.php?p =cell_phone is parsed.
I can give you one more example which is just amazing. If any user accidentally types
http://yourdomainname.com , it automatically converts it into
http://www.yourdomainname.com. And the script is
RewriteEngine on
Options FollowSymLinks
RewriteCond %{HTTP_HOST} yourdomainname.com NC
RewriteRule (.) http://www. yourdomainname.com/1 L,R=301
RewriteRule (A-Za-z0-9:blank:_:digit:.-).html blank-page.php?pagename=1 L
RewriteCond %{REQUEST_METHOD} TRACE
RewriteRule . - F
Script
execution time: Say one of your script files takes much time to
execute. And before it finishes the execution the browser gets
disconnected. In that case you can add this statement to increase or
control the execution time.
php_value max_execution_time 7200
The
fact is that, you can change any php settings with the above statement.
The syntax is php_value %Settings_name% %settings_value%.
I wish to come up with more articles on Apache, PHP and MySQL in days to come. Till then happy learning!