htaccess mod_rewrite based on day of the month

Dear experts

I wish to redirect my domain to subdomain using day of the month.
e.g
5th of the month redirect  ( abc.com and Anything.abc.com ) to five.abc.com
17th of the month redirect ( abc.com and Anything.abc.com )  to  seventeen.abc.com

If visitors type the following url on 5th:
www.abc.com  REDIRECT TO five.abc.com
abc.com REDIRECT TO  five.abc.com
direct.abc.com/download REDIRECT TO five.abc.com/download
whatever.abc.com/images/index.htm REDIRECT TO  five.abc.com/images/index.htm

Note:
If they type
five.abc.com on 6th, they will need to be redirect to six.abc.com as well

Currently i am trying with this codes, but there is a loop error
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteCond %{TIME_DAY} ^1
RewriteRule ^(.*) http://one.abc.com/$1 [R=301,L]
RewriteCond %{TIME_DAY} ^2
RewriteRule ^(.*) http://two.abc.com/$1 [R=301,L]
RewriteCond %{TIME_DAY} ^3
RewriteRule ^(.*) http://three.abc.com/$1 [R=301,L]

List of subdomains
one.abc.com
two.abc.com
three.abc.com
four.abc.com
five.abc.com
six.abc.com
abc.com <- i am not using this
www.abc.com <- I am not using this

Thank you!
subtilAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve BinkCommented:
For month, use TIME_MON, not TIME_DAY.  Also, make sure the redirection can only happen once.  If all these requests are coming in to the same domain, put the rewrite rules only on that domain.  If these rules have to be on all the domains, you'll need to put something in the query string to act as a detection flag.
btanExec ConsultantCommented:
TIME_DAY should still be correct since the day of the month is the required input.
See (TIME) example - http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html#TIME

I am thinking of redirect specific to hostname example of (preferred  Redirect directive over  mod_rewrite - if) but either of these two will still works..
<If "%{HTTP_HOST} != 'www.example.com'">
    Redirect "/" "http://www.example.com/"
</If>

For sites running on a port other than 80:

RewriteCond "%{HTTP_HOST}"   "!^www\.example\.com" [NC]
RewriteCond "%{HTTP_HOST}"   "!^$"
RewriteCond "%{SERVER_PORT}" "!^80$"
RewriteRule "^/?(.*)"        "http://www.example.com:%{SERVER_PORT}/$1" [L,R,NE]

If you wanted to do this generically for all domain names - that is, if you want to redirect example.com to www.example.com for all possible values of example.com, you could use the following recipe:

RewriteCond "%{HTTP_HOST}" "!^www\."                    [NC]
RewriteCond "%{HTTP_HOST}" "!^$"
RewriteRule "^/?(.*)"      "http://www.%{HTTP_HOST}/$1" [L,R,NE]
http://httpd.apache.org/docs/trunk/rewrite/remapping.html#canonicalhost

also a common pitfall specific on looping issue, is due to rerun of the ruleset and there is need to find a terminating rule to end early. The example shared is for URL folder not hostname per se so I am thinking may be easier to go for redirect directive ... pardon as I have not drilled further
L for Last is a useful option to tell the rewrite engine to stop once the rule has been matched. This is what it does — the remaining rules in the .htaccess file are then ignored. However, once a URL has been rewritten, the entire set of rules are then run again on the new URL. If the new URL matches any of the rules, that too will be rewritten and on it goes.

One way to avoid this problem is to keep your ‘real’ pages under a folder path that will never match one of your rules, or that you can exclude from the rewrite rules......

....Excluding a directory
As mentioned above, if you’re rewriting lots of fancy URLs to a collection of real files it can be helpful to put those files in a folder and exclude it from rewrite rules. This helps solve the issue of rewrite rules reapplying to your newly rewritten URL. To exclude a directory, put a rule like this at the top of your file, before your other rules. Our files are in a folder called _source, the dash in the rule means do nothing, and the L flag means the following rules won’t be applied.

RewriteRule ^_source - [L]
http://24ways.org/2013/url-rewriting-for-the-fearful/


Just few cents

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
subtilAuthor Commented:
Thanks!
Will look into it in deep.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.