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: Non www Redirect Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
Keeop
Newbie
Newbie


Joined: 16 November 2006
Online Status: Offline
Posts: 9
Posted: 26 June 2008 at 4:24pm | IP Logged Quote Keeop

Hi,

Can someone please help with the rules to do a redirect for non www to www domains? i.e. from mysite.com to www.mysite.com. However, I need both .com and .co.uk sites to be redirected. I have found code for ISAPI v3 on the site but not for v2 unfortunately.

Thanks.

Keeop

Back to Top View Keeop's Profile Search for other posts by Keeop
 
Spec_David
Newbie
Newbie


Joined: 25 June 2008
Online Status: Offline
Posts: 11
Posted: 27 June 2008 at 8:24am | IP Logged Quote Spec_David


Back to Top View Spec_David's Profile Search for other posts by Spec_David Visit Spec_David's Homepage
 
Spec_David
Newbie
Newbie


Joined: 25 June 2008
Online Status: Offline
Posts: 11
Posted: 27 June 2008 at 8:27am | IP Logged Quote Spec_David

#new condition
RewriteCond Host: .*(mysite)\.com
RewriteRule (.*) http\://www.mysite.com [I,RP]
Back to Top View Spec_David's Profile Search for other posts by Spec_David Visit Spec_David's Homepage
 
Keeop
Newbie
Newbie


Joined: 16 November 2006
Online Status: Offline
Posts: 9
Posted: 27 June 2008 at 10:49am | IP Logged Quote Keeop

Thanks for your response but I was after the rules to rerwrite any .com or any .co.uk to www.xxx.com or .co.uk - i.e. a generic rule to force all to use www. Sorry if I wasn't clear. Would you know how to do that?

Cheers.

Keeop

Back to Top View Keeop's Profile Search for other posts by Keeop
 
Spec_David
Newbie
Newbie


Joined: 25 June 2008
Online Status: Offline
Posts: 11
Posted: 27 June 2008 at 11:49am | IP Logged Quote Spec_David

I am not entirely sure what you want to do.

RewriteCond Host: .*(mysite)\.com
RewriteRule (.*) http\://www.mysite.com [I,RP]

Will rewrite all requests at mysite.com to www.mysite.com

RewriteCond Host: .*(mysite)\.co\.uk
RewriteCond Host: .*(mysite)\.com
RewriteRule (.*) http\://www.mysite.com [I,RP]

Will rewrite all requests at mysite.co.uk and mysite.com to www.mysite.com

If you are looking to rewrite any .com or any .co.uk request to your domain, that is impossible. Your domain must have some unique identifier (ie, mysite). You can't possibly rewrite yahoo.com to your site. On the other hand, if you were looking to force people to use www.mysite.com, then simply don't make a rewrite rule, so that requests at mysite.com will fail.
Back to Top View Spec_David's Profile Search for other posts by Spec_David Visit Spec_David's Homepage
 
Spec_David
Newbie
Newbie


Joined: 25 June 2008
Online Status: Offline
Posts: 11
Posted: 27 June 2008 at 11:50am | IP Logged Quote Spec_David

I re-read your post, I understand what you're saying, but I think you're outside the scope of what re-writes can do.
Back to Top View Spec_David's Profile Search for other posts by Spec_David Visit Spec_David's Homepage
 
Keeop
Newbie
Newbie


Joined: 16 November 2006
Online Status: Offline
Posts: 9
Posted: 27 June 2008 at 6:42pm | IP Logged Quote Keeop

Hi,

I found the rules to write any non-www for any .com but a.) these are just for .com and whenever I try and use .co.uk it seems to fail, and b.) it's for version 3 and if I try and change it for use with version 2 it fails. Anyway, here is the v3 ruleset:

RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http(?%1s)://www.%2%3 [R=301,L]

This can be found in the documentation examples. So, what I'm after is this, but for version 2, and the same thing for .co.uk domains. If it can be done with V3 I think it's within the scope of what the Helicon API can do, it's just that I'm not good enough to convert it to V2 or do the same for .co.uk. So, if you could come up with something based on the example above, I'd be most grateful!

Cheers.

Keeop

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


Joined: 15 August 2002
Location: Russian Federation
Online Status: Offline
Posts: 7468
Posted: 30 June 2008 at 4:09pm | IP Logged Quote Lexey

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


Joined: 16 November 2006
Online Status: Offline
Posts: 9
Posted: 01 July 2008 at 4:45pm | IP Logged Quote Keeop

Thanks Lexey.

Didn't work to start with but I found something similar and so removed a ?

RewriteCond Host: (?!www\.)(.*)
RewriteCond %HTTPS (on)|.*
RewriteRule (.*) http(?2s:)\://www.$1$3 [I,RP]

All working niceley now. Thanks.

Keeop

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


Joined: 15 August 2002
Location: Russian Federation
Online Status: Offline
Posts: 7468
Posted: 03 July 2008 at 6:17pm | IP Logged Quote Lexey

Ops, it was a typo. Your rule is right.
Back to Top View Lexey's Profile Search for other posts by Lexey
 
andrewspringman
Newbie
Newbie


Joined: 11 July 2008
Online Status: Offline
Posts: 1
Posted: 11 July 2008 at 1:28pm | IP Logged Quote andrewspringman

This is a very useful thread.  I like the completely generic approach. 

RewriteCond Host: .*(mysite)\.com
RewriteRule (.*) http\://www.mysite.com [I,RP]

The above would have worked for me OK, but the below is genius!

RewriteCond Host: (?!www\.)(.*)
RewriteCond %HTTPS (on)|.*
RewriteRule (.*) http(?2s:)\://www.$1$3 [I,RP]

I can't get either of them to work though.  I'm sure it's just some newbie issue.  I'm using appliedi.net as my host (windows server using version 2 of ISAPI_Rewrite).  They sent me to this forum because the first approach didn't work.  I've created a .htaccess file and put the following in it.

[ISAPI_Rewrite]
RewriteCond Host: (?!www\.)(.*)
RewriteCond %HTTPS (on)|.*
RewriteRule (.*) http(?2s:)\://www.$1$3 [I,RP]

I'm used to unix servers where .htaccess needs to have specific permissions to work properly.  Is there something similar going on in the windows server?  Any ideas?

Thanks


Back to Top View andrewspringman's Profile Search for other posts by andrewspringman Visit andrewspringman's Homepage
 
Lexey
Moderator Group
Moderator Group


Joined: 15 August 2002
Location: Russian Federation
Online Status: Offline
Posts: 7468
Posted: 12 July 2008 at 12:21pm | IP Logged Quote Lexey

ISAPI_Rewrite 2 configuration files are named "httpd.ini" not ".htaccess".
ISAPI_Rewrite 3 configuration files are named ".htaccess" but it requires different rules syntax.
Back to Top View Lexey's Profile Search for other posts by Lexey
 

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