inicio mail me! View Ehsanul Haque's LinkedIn profile sindicaci;ón

Redirect with .htaccess file

Ever wanted to redirect users from one domain to other or one sub-domain to other without compromising the the file path or query string variables? I’ve come across the requirement when I published my WordPress blog.

For testing, I initially installed WordPress on a testing sub-domain, where I imported all the blog entries and added blog-roll links. After doing so, PHPClasses.org picked up my entries for Grab Yahoo, LinkMeIn and MySpace profile updater as track-back links. Later when I switched to my main sub-domain, I’d to find a way to keep the track-back links as is, and redirect users to the proper locations. The trick was done by .htaccess file.

After reading the apache’s documentation on mod_rewrite module, I’ve successfully implemented it. If you want people accessing http://sub1.yourdomain.com/2/12/some-post-of-yours/ to go to http://sub2.yourdomain.com/2/12/some-post-of-yours/ then in the root of sub1 (first sub-domain) create a .htaccess file and add the following lines:

RewriteEngine On
RewriteRule (.*) http://sub2.yourdomain.com/$1

I have not read much and not sure if there’s any other option to do this more efficiently; but this trick has served my purpose.

htaccess said,

May 16, 2008 @ 8:24 am

[...] come across the requirement when I published my WordPress blog. For testing, I initially installedhttp://ehsan.bdwebwork.com/2008/05/15/redirect-with- [...]

MD.Harisur Rahman [Jewel] said,

May 24, 2008 @ 6:28 am

ThankS boSS

RSS feed for comments on this post · TrackBack URI

Leave a Comment