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 (Forum Locked Forum Locked)
 Helicon Tech : ISAPI_Rewrite 2.x
Subject Topic: Remove www from URLs
Author
Message |
hex1848
Newbie


Joined: 17 January 2005
Posts: 9
Posted: 17 February 2011 at 4:11pm

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
 
Anton
Admin Group


Joined: 30 January 2007
Location: Ukraine
Posts: 10519
Posted: 18 February 2011 at 2:00am

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
 
hex1848
Newbie


Joined: 17 January 2005
Posts: 9
Posted: 21 February 2011 at 9:50am

This worked great. Thank you!
Back to Top
 
hex1848
Newbie


Joined: 17 January 2005
Posts: 9
Posted: 21 February 2011 at 10:03am

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
 
Anton
Admin Group


Joined: 30 January 2007
Location: Ukraine
Posts: 10519
Posted: 22 February 2011 at 2:47am

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
 
hex1848
Newbie


Joined: 17 January 2005
Posts: 9
Posted: 22 February 2011 at 8:38am

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
 
hex1848
Newbie


Joined: 17 January 2005
Posts: 9
Posted: 22 February 2011 at 8:55am

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
 
Anton
Admin Group


Joined: 30 January 2007
Location: Ukraine
Posts: 10519
Posted: 23 February 2011 at 4:07am

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
 
hex1848
Newbie


Joined: 17 January 2005
Posts: 9
Posted: 23 February 2011 at 8:54am

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
 

Sorry, you can NOT post a reply.
This forum has been locked by a forum administrator.

Printable version Printable version
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