Specific Subdomain Redirects
8 posts
• Page 1 of 1
- nemesisdan
- Posts: 5
- Joined: 22 Apr 2014, 09:44
Specific Subdomain Redirects
Hi, here is my problem...
I need to redirect mydomain from non-www to the www. BUT i need to preserve specific subdomains...
Eg.
http://mydomain.com should redirect to http://www.mydomain.com
http://subdomain1.mydomain.com should not redirect and remain the same
http://subdomain2.mydomain.com should redirect to http://www.mydomain.com because i do not want this subdomain.
Basically I have about 5 different subdomains which shouldn't get captured by the non-www redirect, but anything else needs to redirect to www.
Is this possible?
I need to redirect mydomain from non-www to the www. BUT i need to preserve specific subdomains...
Eg.
http://mydomain.com should redirect to http://www.mydomain.com
http://subdomain1.mydomain.com should not redirect and remain the same
http://subdomain2.mydomain.com should redirect to http://www.mydomain.com because i do not want this subdomain.
Basically I have about 5 different subdomains which shouldn't get captured by the non-www redirect, but anything else needs to redirect to www.
Is this possible?
Re: Specific Subdomain Redirects
Hello,
Here's how the rule should look like:
[ISAPI_Rewrite]
RewriteCond Host: ^(?!(?:www|subdomain1\.|something\.|else\.|you\.|need\.|to\.|exclude\.).*)(.*)?mydomain\.com
RewriteRule (.*) http://www.mydomain.com$2 [I,RP]
Here's how the rule should look like:
[ISAPI_Rewrite]
RewriteCond Host: ^(?!(?:www|subdomain1\.|something\.|else\.|you\.|need\.|to\.|exclude\.).*)(.*)?mydomain\.com
RewriteRule (.*) http://www.mydomain.com$2 [I,RP]
- nemesisdan
- Posts: 5
- Joined: 22 Apr 2014, 09:44
Re: Specific Subdomain Redirects
Hi Anton
This is fantastic! Many thanks!
Just a thought, the rule you've posted is a permanent redirect... If at some point in the future I wanted to use subdomain1, would the permanent redirect prevent browsers/servers from accessing this subdomain in the future, even if i add it as a permitted subdomain at that point?
non-www. and subdomain1 should redirect permanently, but should subdomain2 "302" redirect instead? How would I achieve this? Would I need two separate rules that don't conflict with each other?
This is fantastic! Many thanks!
Just a thought, the rule you've posted is a permanent redirect... If at some point in the future I wanted to use subdomain1, would the permanent redirect prevent browsers/servers from accessing this subdomain in the future, even if i add it as a permitted subdomain at that point?
non-www. and subdomain1 should redirect permanently, but should subdomain2 "302" redirect instead? How would I achieve this? Would I need two separate rules that don't conflict with each other?
Re: Specific Subdomain Redirects
"If at some point in the future I wanted to use subdomain1, would the permanent redirect prevent browsers/servers from accessing this subdomain in the future, even if i add it as a permitted subdomain at that point?"
- If you want to use subdomain1 again, just remove it from the rule I have provided and requests to it will no longer be redirected.
If you need a 302 redirect, use [R] instead of [RP] flag.
"Would I need two separate rules that don't conflict with each other?"
- Yes, I believe so.
- If you want to use subdomain1 again, just remove it from the rule I have provided and requests to it will no longer be redirected.
If you need a 302 redirect, use [R] instead of [RP] flag.
"Would I need two separate rules that don't conflict with each other?"
- Yes, I believe so.
- nemesisdan
- Posts: 5
- Joined: 22 Apr 2014, 09:44
Re: Specific Subdomain Redirects
Hi Anton, thanks for the response!
I've probably not explained myself properly...
What I meant was that using the above rule, the invalid domain subdomain1 correctly redirects to the www. version of the domain, but with a permanent redirect. If I subsequently add this domain as a valid subdomain at some point, browers and servers that have already cached the 301 redirect will never reach the valid subdomain and always redirect to the www. version.
I suppose what i'm asking, is there a way to redirect invalid subdomains on a 302 basis, but valid subdomains pass through on a 301 redirect?
I've probably not explained myself properly...
What I meant was that using the above rule, the invalid domain subdomain1 correctly redirects to the www. version of the domain, but with a permanent redirect. If I subsequently add this domain as a valid subdomain at some point, browers and servers that have already cached the 301 redirect will never reach the valid subdomain and always redirect to the www. version.
I suppose what i'm asking, is there a way to redirect invalid subdomains on a 302 basis, but valid subdomains pass through on a 301 redirect?
Re: Specific Subdomain Redirects
Hello,
As far as we know it is incorrect to cache redirects and very few servers/browsers do that, so there shouldn't be any problem with making the subdomain accessible again.
As far as we know it is incorrect to cache redirects and very few servers/browsers do that, so there shouldn't be any problem with making the subdomain accessible again.
- nemesisdan
- Posts: 5
- Joined: 22 Apr 2014, 09:44
Re: Specific Subdomain Redirects
Hi Anton
Thanks for the info! I use Firefox and it does cache 301 redirects meaning I have to flush it if I make a mistake. Often my users will miss-type something or search servers will try different combinations of keywords to find results. For example they may try [email protected] and whilst i'm not currently using that subdomain, if I do at a later date, there is a chance they will never see it. Not a big problem, but still a problem.
Thanks for the info! I use Firefox and it does cache 301 redirects meaning I have to flush it if I make a mistake. Often my users will miss-type something or search servers will try different combinations of keywords to find results. For example they may try [email protected] and whilst i'm not currently using that subdomain, if I do at a later date, there is a chance they will never see it. Not a big problem, but still a problem.
Re: Specific Subdomain Redirects
Hello,
You can set "no-cache" for 301 redirects, cause there is nothing we can do in ISAPI_Rewrite about it.
Also check this thread for some ideas http://stackoverflow.com/questions/6980 ... -redirects
You can set "no-cache" for 301 redirects, cause there is nothing we can do in ISAPI_Rewrite about it.
Also check this thread for some ideas http://stackoverflow.com/questions/6980 ... -redirects
8 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 0 guests