| Author |
|
hex1848 Newbie

Joined: 17 January 2005
Online Status: Offline Posts: 9
|
| Posted: 17 February 2011 at 4:11pm | IP Logged
|
|
|
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
Online Status: Offline Posts: 10520
|
| Posted: 18 February 2011 at 2:00am | IP Logged
|
|
|
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
Online Status: Offline Posts: 9
|
| Posted: 21 February 2011 at 9:50am | IP Logged
|
|
|
This worked great. Thank you!
|
| Back to Top |
|
| |
hex1848 Newbie

Joined: 17 January 2005
Online Status: Offline Posts: 9
|
| Posted: 21 February 2011 at 10:03am | IP Logged
|
|
|
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
Online Status: Offline Posts: 10520
|
| Posted: 22 February 2011 at 2:47am | IP Logged
|
|
|
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
Online Status: Offline Posts: 9
|
| Posted: 22 February 2011 at 8:38am | IP Logged
|
|
|
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
Online Status: Offline Posts: 9
|
| Posted: 22 February 2011 at 8:55am | IP Logged
|
|
|
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
Online Status: Offline Posts: 10520
|
| Posted: 23 February 2011 at 4:07am | IP Logged
|
|
|
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
Online Status: Offline Posts: 9
|
| Posted: 23 February 2011 at 8:54am | IP Logged
|
|
|
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 |
|
| |