I’m writing codes based on the various conditions, choose the one, which suits your need –
site – http://demo.com
sub directory – http://demo.com/mydir/
sub domain – subdom.demo.com
1) Redirection from subdir to subdomain – for All URLs
From – http://www.demo.com/mydir/{article-url}
To – http://subdom.demo.com/ {article-url}
[code autolinks=”false”]
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.demo.com
RewriteRule ^mydir/(.*)$ http://subdom.sample.com/$1 [L,R=301]
[/code]
2) Redirection from subdir to subdomain’s subdir
From – http://www.demo.com/mydir/{article-url}
To – http://subdom.demo.com/subdir/{article-url}
[code autolinks=”false”]
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.demo.com
RewriteRule ^mydir/(.*)$ http://subdom.sample.com/subdir/$1 [L,R=301]
[/code]
3) Redirection from subdir to subdomain
From – http://www.demo.com/mydir/
To – http://subdom.demo.com/
[code autolinks=”false”]
# 301 redirect for main pages
RedirectMatch 301 ^/mydir/$ http://subdom.demo.com/
[/code]
4) Redirection from subdir to subdomain’s sepcific page
Lets say I want to redirect all the pages of my subdirectory to a particular page of my sub-domain, for example
http://www.demo.com/mydir/page1.php
http://www.demo.com/mydir/page2.htm
http://www.demo.com/mydir/file.htm
http://www.demo.com/mydir/abc.html
all of the above to http://subdom.demo.com/mypage.php
[code autolinks=”false”]
# permanent redirect to a particular page
RedirectMatch 301 ^/mydir/$ http://subdom.demo.com/mypage.php
[/code]
Leave a Reply