Active TopicsActive Topics  Display List of Forum MembersMemberlist  HelpHelp   RegisterRegister  LoginLogin
ISAPI_Rewrite 2.x support forum
 Helicon Tech : ISAPI_Rewrite 2.x support forum
Subject Topic: rdirect non-www to www rules help Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
fixer
Newbie
Newbie


Joined: 19 September 2008
Location: United States
Online Status: Offline
Posts: 4
Posted: 19 September 2008 at 12:44pm | IP Logged Quote fixer

Ok.. I am brand new to this, and could not be more of a newb. 

I think what I am trying to do is fairly simple and straightforward... but I need help getting started.
I just installed Rewrite/2 on my 2003 server.
My default httpd.ini file that was created is this:

[ISAPI_Rewrite]

# 3600 = 1 hour
CacheClockRate 3600

RepeatLimit 32

# Block external access to the httpd.ini and httpd.parse.errors files
RewriteRule /httpd(?:\.ini|\.parse\.errors).* / [F,I,O]
# Block external access to the Helper ISAPI Extension
RewriteRule .*\.isrwhlp / [F,I,O]


I have about a dozen sites, and I need to put in a rule to redirect the non-www to www.

I added what I thought was the following default rule at the bottom for one of my many sites as a test:

[ISAPI_Rewrite]

# 3600 = 1 hour
CacheClockRate 3600

RepeatLimit 32

# Block external access to the httpd.ini and httpd.parse.errors files
RewriteRule /httpd(?:\.ini|\.parse\.errors).* / [F,I,O]
# Block external access to the Helper ISAPI Extension
RewriteRule .*\.isrwhlp / [F,I,O]

# Move anything from non- www.example.com -> www.example.com
# e.g. example.com -> www.example.com
RewriteCond %HTTPS off
RewriteCond Host: (?!^www.example.com)(.+)
RewriteRule /(.*) http\://www.example.com/$2 [I,RP]

..of course I changed the www.myexample.com to one of my domain names www.mydomain.com, saved, tested, and while it worked for www.mydomain.com.  It also set ALL of my domains pointing to www.mydomain.com.
This immediately cracked me up, and also has now led me here.

Since I don't know what I'm doing, I don't know what I'm missing.

Basically I need this particular redirect for all my sites...
So is my issue that I just need to add ALL of them in, and then each site address will resolve correctly?  Or have I missed something obvious and simple in what I have done, with my single domain test attempt?

Thanks in advance!

Back to Top View fixer's Profile Search for other posts by fixer
 
Lexey
Moderator Group
Moderator Group


Joined: 15 August 2002
Location: Russian Federation
Online Status: Offline
Posts: 7598
Posted: 19 September 2008 at 2:57pm | IP Logged Quote Lexey

So, you need to redirect anydomain.com to www.anydomain.com, right?

Then try this:

RewriteCond %HTTPS off
RewriteCond Host: (?!www\.)[^.]+\.[^.]+
RewriteRule (.*) http\://www.example.com$1 [I,RP]
Back to Top View Lexey's Profile Search for other posts by Lexey
 
fixer
Newbie
Newbie


Joined: 19 September 2008
Location: United States
Online Status: Offline
Posts: 4
Posted: 19 September 2008 at 3:38pm | IP Logged Quote fixer

Thank you for the quick response.

I just tried it.  Same problem is occurring.

If you enter http://mydomain.com minus the www, it will correctly send to www.mydomain.com.  So the non-www to www issue works.. but... it also takes ALL my sites on that server, and no matter which one I type in an address for, it is going to www.mydomain.com.

As a test, I added two domains to the .ini file, to see if maybe I just needed to have an address in for each separate site on the server.

RewriteCond %HTTPS off
RewriteCond Host: (?!www\.)[^.]+\.[^.]+
RewriteRule (.*) http\://www.mydomain.com$1 [I,RP]

RewriteCond %HTTPS off
RewriteCond Host: (?!www\.)[^.]+\.[^.]+
RewriteRule (.*) http\://www.differentdomain.com$1 [I,RP]

It completely ignored the second entry and sent www.differentdomain.com as well as ALL my other sites to www.mydomain.com

Any ideas?
Maybe because it is a new .ini file fresh from the install, and I don't have enough default entries?  I'm reaching.

Back to Top View fixer's Profile Search for other posts by fixer
 
Lexey
Moderator Group
Moderator Group


Joined: 15 August 2002
Location: Russian Federation
Online Status: Offline
Posts: 7598
Posted: 19 September 2008 at 5:00pm | IP Logged Quote Lexey

Ops, sorry. It is my mistake. Try this rule:

RewriteCond %HTTPS off
RewriteCond Host: (?!www\.)([^.]+\.[^.]+)
RewriteRule (.*) http\://www.$1$2 [I,RP]
Back to Top View Lexey's Profile Search for other posts by Lexey
 
fixer
Newbie
Newbie


Joined: 19 September 2008
Location: United States
Online Status: Offline
Posts: 4
Posted: 19 September 2008 at 5:37pm | IP Logged Quote fixer

I just made the attempt.

With the following:

[ISAPI_Rewrite]

# 3600 = 1 hour
CacheClockRate 3600

RepeatLimit 32

# Block external access to the httpd.ini and httpd.parse.errors files
RewriteRule /httpd(?:\.ini|\.parse\.errors).* / [F,I,O]
# Block external access to the Helper ISAPI Extension
RewriteRule .*\.isrwhlp / [F,I,O]

RewriteCond %HTTPS off
RewriteCond Host: (?!www\.)([^.]+\.[^.]+)
RewriteRule (.*) http\://www.mydomain.com$1$2 [I,RP]

The result is that www.mydomain.com address works fine, however just mydomain.com address has a standard "cannot display page" error.  So the non-www to www 'redirect' is now not working quite right. 

Partial good news is that the other sites on the server are no longer being forced to the same url, and are no longer affected by the entry.

We are getting closer?! ;)

Back to Top View fixer's Profile Search for other posts by fixer
 
Lexey
Moderator Group
Moderator Group


Joined: 15 August 2002
Location: Russian Federation
Online Status: Offline
Posts: 7598
Posted: 20 September 2008 at 6:20am | IP Logged Quote Lexey

You have incorrectly changed the 3rd line of my last rule. Restore it back. My rule should work fine without any modifications.
Back to Top View Lexey's Profile Search for other posts by Lexey
 
fixer
Newbie
Newbie


Joined: 19 September 2008
Location: United States
Online Status: Offline
Posts: 4
Posted: 21 September 2008 at 7:36pm | IP Logged Quote fixer

My mistake, I thought I had to identify the actual domain in the rule.

Lexey you are awesome.  It appears to be working on all sites!

Thank you very much,
Mark

Back to Top View fixer's Profile Search for other posts by fixer
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum