htaccess mod_rewrite based on day of the month

Dear experts

I wish to redirect my domain to subdomain using day of the month.
5th of the month redirect  ( and ) to
17th of the month redirect ( and )  to

If visitors type the following url on 5th:  REDIRECT TO REDIRECT TO REDIRECT TO REDIRECT TO

If they type on 6th, they will need to be redirect to as well

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

List of subdomains <- i am not using this <- I am not using this

Thank you!
Who is Participating?

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

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 -

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} != ''">
    Redirect "/" ""

For sites running on a port other than 80:

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

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

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

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]

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:
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.