htaccess – frendly URL – CMS Made simple

To have pretty URL in CMS made simple it is really easy if  you don not move the website from root in a folder or on a subdomain.

As long as you know what is htaccess file all is fine. If you do not the follow the example:

Let suppose the website was done in development area (most complex scenario: in a subdomain and in a subfolder):

name of the website is: company.com.au

it was developend in: dev1.development.com.au

This is the .htaccess content:

————–BEGIN————-

Options +FollowSymLinks
RewriteEngine on
RewriteBase /company.com.au/

# 301 Redirect all requests that don’t contain a dot or trailing slash to
# include a trailing slash
RewriteCond %{HTTP_HOST} ^dev1.development.com.au/company.com.au
RewriteRule (.*) http://dev1.development.com.au/$1 [R=301,L]

# URL Filtering helps stop some hack attempts
#IF the URI contains a “http:”

RewriteCond %{QUERY_STRING} http\: [OR]

#OR if the URI contains a “[”

RewriteCond %{QUERY_STRING} \[ [OR]

#OR if the URI contains a “]”

RewriteCond %{QUERY_STRING} \] [OR]

#OR if the URI contains a “<script>”

RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]

#OR script trying to set a PHP GLOBALS variable via URL

RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]

#OR any script trying to modify a _REQUEST variable via URL

RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule ^.*$ – [F,L]

# END Filtering

# CMSMS Rewriting – Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
# Set assume mod_rewrite to true in config.php and clear CMSMS cache

RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]

—————END ———————-

Let suppose the website will be moved in the production :

name of the website is: company.com.au

This is the new  .htaccess content (Only the top is changed – see bolded):

————–BEGIN————-

Options +FollowSymLinks
RewriteEngine on
RewriteBase /

# 301 Redirect all requests that don’t contain a dot or trailing slash to 
# include a trailing slash
RewriteCond %{HTTP_HOST} ^company.com.au
RewriteRule (.*) http://www.company.com.au/$1 [R=301,L]

# URL Filtering helps stop some hack attempts
#IF the URI contains a “http:”

RewriteCond %{QUERY_STRING} http\: [OR]

#OR if the URI contains a “[”

RewriteCond %{QUERY_STRING} \[ [OR]

#OR if the URI contains a “]”

RewriteCond %{QUERY_STRING} \] [OR]

#OR if the URI contains a “<script>”

RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]

#OR script trying to set a PHP GLOBALS variable via URL

RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]

#OR any script trying to modify a _REQUEST variable via URL

RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule ^.*$ – [F,L]

# END Filtering

# CMSMS Rewriting – Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
# Set assume mod_rewrite to true in config.php and clear CMSMS cache

RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+)$ index.php?page=$1 [QSA]

—————END ———————-

Leave a Reply

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