Apache 2 HTTP Server

Apache is the most popular web server in existence. Most Linux distributions offer packages to install. You can read more about this at Apache Org.

Setting up a virtual domain is easy.

On some Linux distributions, you may need to run additional commands to enable the virtual host. Please refer to your Linux distribution on administrating Apache.

.htaccess Mod Rewrite URLs

In your apache virtual root folder create a .htaccess file. This will steer all URI requests to main.php to be validated and routed (except favicon.ico and robots.txt). You should also create a favicon.ico and robots.txt file.

It is strongly recommended that you use a canonical URL to avoid Search Engine Optimization (SEO) penalties on duplicate pages. Search engines like Google will penalize websites that have pages with the same content but with different URL representation. For example http://www.site.com/hello is the same as http://site.com/hello. Therefore, it is best to force the canonical base URL to either have the www in it or not.

In the mod rewrite code below, we use the non-www canonical URL. To use this, uncomment out the two lines and replace the domain name with your own.

#===========================================================================================
# Filename: .htaccess
# Purpose: Local Apache HTTP configuration file
# Developer: Kerry Kobashi
# Company: Qlicksoft
#
# .htaccess is the local configuration file that overrides the global virtual
# host configuration file. This file is called for every URI request.
#
# We use this to:
#  1) Avoid changing the global virtual host config which requires reboot
#  2) Allow access to certain files
#  3) Force all URI requests to a bootstrap router (main.php)
#
# Notes:
#  Always use the hash at the beginning with no spaces for comments to avoid HTTP 500
#  Best to not indent to keep comments lined up with code
#  Using .htaccess can make a small slowdown in performance
#  ServerName must be set correctly in your virtual host configuration file
#  You must use a DirectoryIndex even though you are rewriting
#
#   <VirtualHost *:80>
#     ServerName domain.com
#     ServerAlias www.domain.com
#     DocumentRoot /var/www/domain.com/
#     DirectoryIndex main.php
#   </VirtualHost>
#
#  Request for images, css, video, etc. must mirror the full path filename with URI
#  Always check Apache error logs in case of .htaccess problems
#===========================================================================================

<IfModule mod_rewrite.c>

# By default mod rewrite is off
RewriteEngine on

# Allow some resources to go through without being routed
RewriteRule ^favicon.ico$ %{SERVER_NAME}/favicon.ico [NC]
RewriteRule ^robots.txt$ %{SERVER_NAME}/robots.txt [NC]

# Force canonical URL to be www-less for SEO to avoid duplicate pages
# Uncomment next two lines and insert your domain 
# RewriteCond %{HTTP_HOST} !^(domain\.com)?$ [NC]
# RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]

# If resource requested doesn't exist route using main.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .$ main.php
</IfModule>