| Author |
|
Poke Alex Newbie

Joined: 06 October 2008 Location: United States
Online Status: Offline Posts: 10
|
| Posted: 06 October 2008 at 10:02am | IP Logged
|
|
|
Hi everyone,
Sorry to be requiring this type of clarification; I know similar requests have been made before but I'm very new to this.
What I have is several rules that I need to follow.
First, we have specific subdomains of an alias domain that are being utilized for marketing purposes. They are redirecting users to the flagship site:
sub1.domain1.edu -> www.domain2.domain3.edu/folder1?redir=sub1.domain1.edu
But, these are to be individually managed, and sub1 does not necessarily match folder1, if that makes any sense.
Furthermore, any subs *not* explicitly listed should default to the flagship homepage:
subX.domain1.edu -> www.domain2.domain3.edu/
Currently we have *.domain1.edu registered to point to the server, and the subs area managed through CFM code on the homepage (blech). I would like to get this out of our page code now that we have ISAPI_Rewrite purchased, but I am very confused how to manage this.
Much appreciated! Thanks in advance.
Edited by Poke Alex - 06 October 2008 at 10:03am
|
| Back to Top |
|
| |
Anton Moderator Group

Joined: 30 January 2007 Location: Ukraine
Online Status: Offline Posts: 4837
|
| Posted: 07 October 2008 at 3:13am | IP Logged
|
|
|
Please try to use the following config:
RewriteCond %{HTTP_HOST} ^((?:sub1|sub2|sub3)\.domain1\.edu)$ [NC]
RewriteRule .? http://www.domain2.domain3.edu/folder1?redir=%1 [NC,R=301,L]
RewriteCond %{HTTP_HOST} ^(?!(?:www|sub1|sub2|sub3))(.+)\.domain1\.edu)$ [NC]
RewriteRule .? http://www.domain2.domain3.edu/[NC,R=301,L]
__________________ Regards,
Anton
|
| Back to Top |
|
| |
Poke Alex Newbie

Joined: 06 October 2008 Location: United States
Online Status: Offline Posts: 10
|
| Posted: 07 October 2008 at 9:31am | IP Logged
|
|
|
Thank you, Anton. This looks very much like what I'll need. One additional question, should this go in the .htaccess file in my web root folder, or is that the wrong place for this?
|
| Back to Top |
|
| |
Poke Alex Newbie

Joined: 06 October 2008 Location: United States
Online Status: Offline Posts: 10
|
| Posted: 07 October 2008 at 9:35am | IP Logged
|
|
|
Nevermind, it looks like this should go in my httpd.conf file. Is that right?
|
| Back to Top |
|
| |
Anton Moderator Group

Joined: 30 January 2007 Location: Ukraine
Online Status: Offline Posts: 4837
|
| Posted: 08 October 2008 at 2:17am | IP Logged
|
|
|
Yes, guess you need it in httpd.conf.
__________________ Regards,
Anton
|
| Back to Top |
|
| |
Poke Alex Newbie

Joined: 06 October 2008 Location: United States
Online Status: Offline Posts: 10
|
| Posted: 15 October 2008 at 9:25am | IP Logged
|
|
|
Thanks so much for your help! It works great.
One additional question: I am applying the same rules across multiple load-balanced servers. Since these servers all have different license keys for ISAPI_Rewrite 3, I cannot simply copy the .conf file across servers.
For ease of management, I'd like to use a map file for this instead. Any pointers on how I might set up my values in a map file, and how to apply the rule in my conf file?
|
| Back to Top |
|
| |
Anton Moderator Group

Joined: 30 January 2007 Location: Ukraine
Online Status: Offline Posts: 4837
|
| Posted: 16 October 2008 at 2:30am | IP Logged
|
|
|
The best idea is probably to write a script that would copy all the rules from httpd.conf (without regisration info) to new httpd.conf and
then prepend it with proper regisration info.
__________________ Regards,
Anton
|
| Back to Top |
|
| |
Poke Alex Newbie

Joined: 06 October 2008 Location: United States
Online Status: Offline Posts: 10
|
| Posted: 16 October 2008 at 10:21am | IP Logged
|
|
|
Ah yes, now you're getting into a bigger issue with our file migration and QA system - the issue being we don't have one. When we do, I'll be sure that we add special handlers for ISAPI_Rewrite files.
In the meantime, can file mapping help?
|
| Back to Top |
|
| |
Anton Moderator Group

Joined: 30 January 2007 Location: Ukraine
Online Status: Offline Posts: 4837
|
| Posted: 17 October 2008 at 5:48am | IP Logged
|
|
|
Do you want to have map file for ISAPI_Rewrite registration info?
Can you please your idea a little bit further.
__________________ Regards,
Anton
|
| Back to Top |
|
| |
Poke Alex Newbie

Joined: 06 October 2008 Location: United States
Online Status: Offline Posts: 10
|
| Posted: 27 October 2008 at 2:10pm | IP Logged
|
|
|
Hi Anton,
Back to my original question, it seems the first answer has been causing problems.
While I have no problem explicitly capturing subdomains in the first example:
sub1.domain1.edu -> www.domain2.domain3.edu/folder1?redir=sub1.domain1.edu
The second situation seems to be more complicated. Basically, I am using the first set of rules many times to capture many subdomains. After all have been captured, I need a RewriteCond that handles anything left over.
Basically if a person enters keyword1.mydomain.edu or keyword2.mydomain.edu or www.mydomain.edu the redirect captures them because I've explicitly told it to. That works great.
But if someone enters poopyhead.mydomain.edu OR anything else I HAVEN'T explicitly defined I want it to land somewhere else.
|
| Back to Top |
|
| |
Anton Moderator Group

Joined: 30 January 2007 Location: Ukraine
Online Status: Offline Posts: 4837
|
| Posted: 28 October 2008 at 6:01am | IP Logged
|
|
|
Please try to use the following rules:
RewriteCond %{HTTP_HOST} ^((?:sub1|sub2|sub3)\.domain1\.edu)$ [NC]
RewriteRule .? http://www.domain2.domain3.edu/folder1?redir=%1 [NC,R=301,L]
RewriteCond %{HTTP_HOST} ^(?!(?:www|sub1|sub2|sub3))(.+)\.domain1\.edu)$ [NC]
RewriteRule .? http://www.somewhere.else.edu/ [NC,R=301,L]
__________________ Regards,
Anton
|
| Back to Top |
|
| |
Poke Alex Newbie

Joined: 06 October 2008 Location: United States
Online Status: Offline Posts: 10
|
| Posted: 28 October 2008 at 8:12am | IP Logged
|
|
|
Anton, I really appreciate it - but I think my meaning isn't coming across because that rule puts my server into a loop.
Here's what I'm trying to accomplish... (I'll use real world examples since I think that will be clearer.)
We have a website for University of Rochester Medical Center: http://www.urmc.rochester.edu. On it are many different departmental sites (such as www.urmc.rochester.edu/surgery).
The University also has registered (through a different owner, unfortunately) *.urmc.edu as an alias. This is done for marketing purposes. Now, in our httpd.conf file, it's up to me to sort out the "real" subdomains of urmc.edu from the "fake".
So, we have some subdomains that should be captured and handled, for example:
heart.urmc.edu -> www.urmc.rochester.edu/cardiology/cp/heart
menshealth.urmc.edu -> www.urmc.rochester.edu/mens-health
And so on. I can capture these one at a time (and they are added frequently) using your first rule, and have done so successfully.
We also have some people distributing their links using the alias instead of the full domain, such as www.urmc.edu/surgery. We probably won't be able to anticipate these are there are hundreds of subfolders, so I would like requests of this format to be handled:
www.urmc.edu/X -> www.urmc.rochester.edu/X
Finally, since the alias is registered as a wildcard, for indexing and SEO reasons we are trying to handle the last situation where we disallow any non-specified subdomains of the alias.
Therefore to sum up:
ortho.urmc.edu (valid) -> www.urmc.rochester.edu/ortho
www.urmc.edu/ortho (valid) -> www.urmc.rochester.edu/ortho
urthu.urmc.edu (invalid) -> www.urmc.rochester.edu
There are other domains and aliases as well but I can handle them similarly.
Please keep in mind, ortho.urmc.edu is a rare case where the subdomain matches the end folder name; this won't always be the case (see heart.urmc.edu above) so I need to handle each of those individually.
Edited by Poke Alex - 28 October 2008 at 8:16am
|
| Back to Top |
|
| |
Anton Moderator Group

Joined: 30 January 2007 Location: Ukraine
Online Status: Offline Posts: 4837
|
| Posted: 28 October 2008 at 8:57am | IP Logged
|
|
|
Please try the following:
RewriteBase /
#redirects for individual departments
RewriteCond %{HTTP_HOST} ^heart\.urmc\.edu$ [NC]
RewriteRule .? http://www.urmc.rochester.edu/cardiology/cp/heart [NC,R=301,L]
RewriteCond %{HTTP_HOST} ^menshealth\.urmc\.edu$ [NC]
RewriteRule .? http://www.urmc.rochester.edu/mens-health [NC,R=301,L]
RewriteCond %{HTTP_HOST} ^ortho\.urmc\.edu$ [NC]
RewriteRule .? http://www.urmc.rochester.edu/ortho [NC,R=301,L]
#www.urmc.edu/X -> www.urmc.rochester.edu/X
RewriteCond %{HTTP_HOST} ^www\.urmc\.edu$ [NC]
RewriteRule (.*) http://www.urmc.rochester.edu/$1 [NC,R=301,L]
#everything else not specified in previous rules (like urthu.urmc.edu)
RewriteCond %{HTTP_HOST} ^(.+)\.urmc\.edu$ [NC]
RewriteRule .? http://www.urmc.rochester.edu [NC,R=301,L]
__________________ Regards,
Anton
|
| Back to Top |
|
| |
Poke Alex Newbie

Joined: 06 October 2008 Location: United States
Online Status: Offline Posts: 10
|
| Posted: 28 October 2008 at 9:09am | IP Logged
|
|
|
THANK YOU! I am in your debt. One thing - I changed the /X rule to:
RewriteCond %{HTTP_HOST} ^www\.urmc\.edu$ [NC]
RewriteRule (.*) http://www.urmc.rochester.edu$1 [NC,R=301,L]
since I was getting a result of www.urmc.rochester.edu//subfolder.
As a last question, is there a way to make the www optional in the condition above?
So that
urmc.edu/surgery AND www.urmc.edu/surgery are both captured? I tried ^(www)?\.urmc\.edu$ but that didn't work...
|
| Back to Top |
|
| |
Anton Moderator Group

Joined: 30 January 2007 Location: Ukraine
Online Status: Offline Posts: 4837
|
| Posted: 30 October 2008 at 5:05am | IP Logged
|
|
|
It should be:
RewriteCond %{HTTP_HOST} ^(www\.)?urmc\.edu$ [NC]
RewriteRule (.*) http://www.urmc.rochester.edu$1 [NC,R=301,L]
__________________ Regards,
Anton
|
| Back to Top |
|
| |
Poke Alex Newbie

Joined: 06 October 2008 Location: United States
Online Status: Offline Posts: 10
|
| Posted: 30 October 2008 at 8:52am | IP Logged
|
|
|
Ahhh, thank you Anton! You are an indispensable resource! I believe I am beginning to make sense of all this.
|
| Back to Top |
|
| |