This forum has been moved here:
Helicon Tech Community Forum

  Active TopicsActive Topics  Display List of Forum MembersMemberlist  HelpHelp   RegisterRegister  LoginLogin
ISAPI_Rewrite 2.x
 Helicon Tech : ISAPI_Rewrite 2.x
Subject Topic: Remove www from URLs Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
hex1848
Newbie
Newbie


Joined: 17 January 2005
Online Status: Offline
Posts: 9
Posted: 17 February 2011 at 4:11pm | IP Logged Quote hex1848

I'm trying to remove www from URL's when typed in by the
user. Example rewrites are as follows:

https://www.test.dev.domain.com/default.htm =>
https://test.dev.domain.com/default.htm

https://www.test.domain.com => https://test.domain.com

Using the built in RegExp tester, I can set the following
parameters and get the results I expect:

Regular Expression: (.*)www\.(.*)\.domain\.com(.*)
Test String: https://test.dev.domain.com/
Format String: $1$2.domain.com$3

Format Result: https://test.dev.domain.com/

I set up this rule, but it doesn't seem to work:

RewriteRule (.*)www\.(.*)\.domain\.com(.*)
$1$2.domain.com$3 [I,RP]

Can someone please point me in the right direction?
Back to Top View hex1848's Profile Search for other posts by hex1848
 
Anton
Admin Group
Admin Group


Joined: 30 January 2007
Location: Ukraine
Online Status: Offline
Posts: 10520
Posted: 18 February 2011 at 2:00am | IP Logged Quote Anton

If you need it for https requests only, the rules should be:

RewriteCond %HTTPS .*on.*
RewriteCond Host: www\.((?:.*\.)?domain\.com)
RewriteRule (.*) https\://$1$2 [I,RP]

__________________
Regards,
Anton
Back to Top View Anton's Profile Search for other posts by Anton
 
hex1848
Newbie
Newbie


Joined: 17 January 2005
Online Status: Offline
Posts: 9
Posted: 21 February 2011 at 9:50am | IP Logged Quote hex1848

This worked great. Thank you!
Back to Top View hex1848's Profile Search for other posts by hex1848
 
hex1848
Newbie
Newbie


Joined: 17 January 2005
Online Status: Offline
Posts: 9
Posted: 21 February 2011 at 10:03am | IP Logged Quote hex1848

Now what if we need it to be http/https neutral. I need
the redirect to happen before the HTTPS redirect happens
because the wildcard SSL cert we have only works on a sub
domain. If the HTTPS redirect happens before we remove
the www, we get an SSL error.


I tried to modify your rule to remove the HTTPS
requirement, but it doesn't work exactly how I thought it
would. Here is our current httpd.ini:

---
[ISAPI_Rewrite]

#Remove www from *.domain.com domains
RewriteCond Host: www\.((?:.*\.)?domain\.com)
RewriteRule (.*) $1$2 [I,RP]

#Redirect non-HTTPS to HTTPS
RewriteCond %HTTPS (?!on).*
RewriteCond Host: (.*)
RewriteRule (.*) https\://$1$2 [I,RP]
---

What happens here (when typing www.test.dev.domain.com/
into the browser, is that it ends up appending the
test.dev.domain.com/ over and over and over again:

Example:

https://www.test.dev.domain.com/test.dev.domain.com/test.
dev.domain.com/test.dev.domain.com/test.dev.domain.com/te
st.dev.domain.com/test.dev.domain.com/test.dev.domain.com
/test.dev.domain.com/...

Edited by Vyacheslav - 21 February 2011 at 8:48pm


__________________
Cigarsmokers.com - Cigar Forum
Back to Top View hex1848's Profile Search for other posts by hex1848
 
Anton
Admin Group
Admin Group


Joined: 30 January 2007
Location: Ukraine
Online Status: Offline
Posts: 10520
Posted: 22 February 2011 at 2:47am | IP Logged Quote Anton

You are not the first to want this functionality, but unfortunately it's impossible to have such transformation before cert check, as no
filter can be run before IIS itself...

__________________
Regards,
Anton
Back to Top View Anton's Profile Search for other posts by Anton
 
hex1848
Newbie
Newbie


Joined: 17 January 2005
Online Status: Offline
Posts: 9
Posted: 22 February 2011 at 8:38am | IP Logged Quote hex1848

Thanks for the reply. So how do I get it to not repeat the
match phrase over and over and over again with my rule
above?

Example:

https://www.test.dev.domain.com/test.dev.domain.com/test.
dev.domain.com/test.dev.domain.com/test.dev.domain.com/te
st.dev.domain.com/test.dev.domain.com/test.dev.domain.com
/test.dev.domain.com/...
Back to Top View hex1848's Profile Search for other posts by hex1848
 
hex1848
Newbie
Newbie


Joined: 17 January 2005
Online Status: Offline
Posts: 9
Posted: 22 February 2011 at 8:55am | IP Logged Quote hex1848

To clarify my last question:

How do I get

https://www.test.dev.domain.com/ to redirect to
https://test.dev.domain.com/

AND/OR

http://www.test.dev.domain.com/ to redirect to
http://test.dev.domain.com/

(http/https neutral)

Back to Top View hex1848's Profile Search for other posts by hex1848
 
Anton
Admin Group
Admin Group


Joined: 30 January 2007
Location: Ukraine
Online Status: Offline
Posts: 10520
Posted: 23 February 2011 at 4:07am | IP Logged Quote Anton

Please try to have it the following way:

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

__________________
Regards,
Anton
Back to Top View Anton's Profile Search for other posts by Anton
 
hex1848
Newbie
Newbie


Joined: 17 January 2005
Online Status: Offline
Posts: 9
Posted: 23 February 2011 at 8:54am | IP Logged Quote hex1848

Thank you for your help Anton. This is working exactly as
we need it to.. I had to make one change to your rule:

RewriteCond %{HTTPS} .*(on)?.*
RewriteCond Host: www\.((?:.*\.)?domain\.com)
RewriteRule (.*) http(?1s)\://$1$2$3
[I,RP]
Back to Top View hex1848's Profile Search for other posts by hex1848
 

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