.htaccess Tips

Hypertext Access, commonly shortened to htaccess, is a configuration file which controls the directory it is placed in and all the subdirectories underneath it. It’s an incredibly useful feature which allows webmasters to control how many aspects of their website works. You can redirect pages, change the extensions of pages, password protect directories and much much more.
So here I write “Rewriting tip using .htaccess” file and how to “Redirect sub domain to sub folder”.

Rewriting tip using .htaccess:

Let us take an example,

suppose Original URL:

and we want our Rewriting URL like below:

Below is the .htaccess Code for the above example
RewriteEngine On

RewriteRule ^([a-zA-Z0-9_-]+)/\followers$ followers.php?id=$1

RewriteRule ^([a-zA-Z0-9_-]+)/\following$ following.php?id=$1

Redirect sub domain to sub folder:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^demos\.qualitytuts\.com$
RewriteCond %{REQUEST_URI} !^/demos/
RewriteRule (.*) /demos/$1

RewriteEngine On

RewriteCond %{HTTP_HOST} ^labs\.qualitytuts\.com$
RewriteCond %{REQUEST_URI} !^/labs/
RewriteRule (.*) /labs/$1

In the above code you have to replace your sub-domain and directory name.


Author: Dheeraj Dhawan

I'm a web developer / PHP programmer. I am also working on custom plugin development of wordpress.

Leave a Reply

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