How to configure httpd.conf file for a new website ?

htdocs

In this article I am going to explain how to configure httpd.conf file at Apache web server level for a single website, the httpd.conf file is the main configuration file for Apache web server  and it allows us to modify or add configuraiton of the apache webserver features and functionalities and you find it under “apache/conf/” folder here, I am going to cover basic features which are required to setup a single website

I have new domain name called www.greyarea.in and on hitting this domain name it should redirect to greyarea specific index.html document which is placed under htdocs folder of Apache server

First we need to have VirtualHost entry for greyarea domain in httpd.conf file, every VirtualHost entry maps to one website , on a single machine we can have more than one VirtualHost entries and each VirtualHost entry maps to different websites

VirtualHost Configuration :

The below VirtualHost entry configuration in httpd.conf file helps us to setup a confiugaration for www.greyarea.in website

Here, I am using name-based virtual hosting because the server which I am going to setup is shared to many different hosts

You can change it to IP-based virtual hosting by removing “*” and keeping IP-address “<VirtualHost 127.0.0.1:80>”

The DocumentRoot is the directory which contains your greyarea specific document’s ( html, css , js etc… ), any request which is coming from the client the server first looks for that file in the default folder which is specified in “DocumentRoot /Apache/htdocs”

The servername specifies host name here, www.greyarea.in is the host name

The Rewrite Url’s work’s only when the RewriteEngine is On so, we must add “RewriteEngine On” at greyarey specific VirtualHost, we can Off it by setting up “RewriteEngine Off”, but if you make it Off the rewrite url’s which you have written will not work

What if end user is trying to open non existing page something like this www.greyarea.in/nonexistingpage.html and how can we handle this there the built in feature of Apache server will help us and we need to configure ErrorDocument for 404 status code , we can add ErrorDocument either at virtualhost level or global, the ErrorDocument configuration’s which are added at virtualhost will be applicable to only for partiular website

ErrorDocument 404 /pagenotfound.html

Redirect to home page :

The below confguration will display index page for www.greyarea.in host entry

Short to long Url :

The below configuration helps us when you enter http://www.greyarea.in/index.html in the address bar redirect to http://www.greyarea.in/greyarea/index.html

Friendly Urls :

Actually in the below configuration the blogs folder does not exist but the url which start’s with “/blogs” will automatically map to blog-template folder

Handle QueryString’s :

The url’s which contains key=value will automatically transforms to friendly url’s in order to work this properly the friendly url’s folder path’s must exist

Build query string based on friendly url’s  :

if you enter “http://www.greyarea.in/greyarea/about/search”  in the address then the below configuration will build new url’s something like this “http://www.geometrixx.com/greyarea/about.html?key=search”

Trim .html extension :

The below configuration trims the .html extension in the url, “http://greyarea.in/greyarea/index.html” to “http://greyarea.in/greyarea/index”

Leave a Reply

Your email address will not be published. Required fields are marked *

Visit Us On FacebookVisit Us On Google PlusVisit Us On Twitter