0

Use .htaccess file for URL Rewriting

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.

use-htaccess-file-for-url-rewriting-1

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

use-htaccess-file-for-url-rewriting-2

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

http://growwebsite.com/profile.php?username=officialvikas01
to
http://growwebsite.com/officialvikas01

Friends URL with Two Parameters

Here the first parameter allows [a-zA-Z0-9_-] and second parameter allows only number [0-9]
http://growwebsite.com/friends.php?username=officialvikas01&page=2
to
http://growwebsite.com/friends/officialvikas01/2

Hiding File Extension

http://www.growwebsite.com/index.html
to
http://www.growwebsite.com/index

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 *