Simple help needed

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 4
Joined: 30 Jan 2017, 19:30

Simple help needed

30 Jan 2017, 19:36

I have two URLS, domain.com and domain.org. I want to do the following three things in the htaccess file:

direct non www to go to www
direct .org to go to .com
direct any to https

So, in the end, no matter whether a user navigates to:
domain.com
domain.org
http://www.domain.com
http://www.domain.org
...or any subpage of either

it always is directed to:

https://www.domain.com or https://www.domain.com/subpage

I have tried many iteration of code for ISAPI_Rewrite 3.0 and cannot get it right. Please help!

User avatar
Posts: 402
Joined: 06 Mar 2012, 11:59

Re: Simple help needed

02 Feb 2017, 10:36

Hello.

The correct code would be:

RewriteEngine On
RewriteCond %{HTTPS} !on [NC]
RewriteCond %{HTTP_HOST} !^www\.domain\.org [NC]
RewriteRule (.*) https\://www.domain.com$1 [R,QSA]


The rules above mean anything that does not start with https://www.domain.com will be redirected to https://www.domain.com, preserving page requested and parameters. These rules should be placed in the .htaccess file in the IIS website with bindings to all www and non-www and org and com versions of the domain.

User avatar
Posts: 4
Joined: 30 Jan 2017, 19:30

Re: Simple help needed

09 Feb 2017, 17:43

Thank you. It works under most circumstances, but this doesn't work with the code provided:

If you go to a specific page on the HTTP, the code takes out the slash between the root and the individual page:

http://www.domain.com/search_1.asp/

https://www.domain.comsearch_1.asp/

User avatar
Posts: 402
Joined: 06 Mar 2012, 11:59

Re: Simple help needed

10 Feb 2017, 11:48

Agree, in .htaccess context the rule should look like:

RewriteEngine On
RewriteCond %{HTTPS} !on [NC]
RewriteCond %{HTTP_HOST} !^www\.domain\.org [NC]
RewriteRule (.*) https\://www.domain.com/$1 [R,QSA]

User avatar
Posts: 4
Joined: 30 Jan 2017, 19:30

Re: Simple help needed

10 Feb 2017, 14:08

Thanks. I thought that was the case. Will make the change.

User avatar
Posts: 4
Joined: 30 Jan 2017, 19:30

Re: Simple help needed

14 Feb 2017, 19:02

OK ... that is better, but not quite. This works:

http://domain.com/login.asp


Adds the www. and changes to:

https://www.domain.com/login.asp


BUT the same starting with the HTTPS doesn't add the www.

https://domain.com/login.asp


Stays:

https://domain.com/login.asp


but should change to:

https://www.domain.com/login.asp


How do I edit your the code above to add the www. ?

Thanks

User avatar
Posts: 1
Joined: 08 Feb 2018, 06:26

Good Work

08 Feb 2018, 06:31

Excellent and nice article. when user want to get important information then visit our site.
https://fullpcsoftz.com/superantispyware-professional-crack-serial-license-key/

User avatar
Posts: 1
Joined: 22 Dec 2017, 03:23

Re: Simple help needed

05 Jun 2018, 01:42

Use SSL to switch to https, I also made a real move to https all my pages, for example:
http://happywheels24.com --> https://happywheels24.com

User avatar
Posts: 92
Joined: 01 Dec 2012, 14:22

Re: Simple help needed

28 Sep 2018, 18:30

brossyg wrote:OK ... that is better, but not quite. This works:

http://domain.com/login.asp


Adds the www. and changes to:

https://www.domain.com/login.asp


BUT the same starting with the HTTPS doesn't add the www.

https://domain.com/login.asp


Stays:

https://domain.com/login.asp


but should change to:

https://www.domain.com/login.asp


How do I edit your the code above to add the www. ?

Thanks


I have the same issue - did you get a solution?

I've been forced to use two separate rules:

#Redirect non-HTTPS to HTTPS
RewriteCond %{HTTP:Host} (.*)
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (.*)
RewriteRule .? https://%1%2 [R,L]

#redirect the non-canonical domains
RewriteCond %{HTTP_HOST} !www\.domain\.com$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/$1 [L,R=301]

Which works, but it would seem there should be a way to do this in one hit.

User avatar
Posts: 92
Joined: 01 Dec 2012, 14:22

Re: Simple help needed

28 Sep 2018, 18:41

Not sure why this:

#redirect the non-canonical domains
RewriteCond %{HTTP_HOST} !www\.domain\.com$ [NC,OR]
RewriteCond %(HTTPS) off
RewriteRule ^(.*)$ https://www.domain.com/$1 [L,QSA,R=301]


... doesn't work.

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 10 guests