Use .htaccess file for URL Rewriting

Spread the love

using .htaccess you can easily configure and redirect Apache Web Server file system. This post will explain you how to create friendly URLs, sub domain directory re-directions and many more.

Note: .htaccess file will be in hidden format, please change your folder and file settings to view this file.

How to Create a .htaccess File?

Open any text editor application and file save as with .htaccess name and enable mod_rewrite extension in php.ini file in Apache Web Server configurations.

Disable directory Listing

If you want to disable folder files listing, include following code.


Error Pages
Here error page is redirecting to error.html.


RewriteEngine On it is turn on Rewrite Rules in Apache Server. if you want to turn off, just change the value to off.

Domain Redirection

.htacces code for redirecting growwebsite.com to www.growwebsite.com

Sub Domain Redirection
Sub domain redirection mapping to folder. Here http://www.growwebsite.com is connecting to website_folder folder.

Here http://subdomain.growwebsite.com is connecting to subdomain_folder folder.

Old Domain Redirection
htaccess code for redirecting old domain(abc.com) to new domain(xyz.com).

Friendly URLs
Friendly/Pretty URLs help in search engine rankings.

Profile URL

Profile parameter allows [a-zA-Z0-9_-] these inputs. More help read Understanding Regular Expression


Friends URL with Two Parameters

Here the first parameter allows [a-zA-Z0-9_-] and second parameter allows only number [0-9]

Hiding File Extension


Hope it will Help You and please subscribe me and like my facebook page :

and make me proud.By the way if you face any problem then let me know in comment section below

Leave a Reply

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