.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:
Eg:http://twitter.com/followers.php?id=qualitytuts

and we want our Rewriting URL like below:
Eg:http://twitter.com/qualitytuts/followers

Below is the .htaccess Code for the above example
[php]
RewriteEngine On

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

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

Redirect sub domain to sub folder:

[php]
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
[/php]

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 *