Simple help needed
10 posts
• Page 1 of 1
Simple help needed
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!
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!
Re: Simple help needed
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.
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.
Re: Simple help needed
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/
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/
Re: Simple help needed
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]
RewriteEngine On
RewriteCond %{HTTPS} !on [NC]
RewriteCond %{HTTP_HOST} !^www\.domain\.org [NC]
RewriteRule (.*) https\://www.domain.com/$1 [R,QSA]
Re: Simple help needed
OK ... that is better, but not quite. This works:
Adds the www. and changes to:
BUT the same starting with the HTTPS doesn't add the www.
Stays:
but should change to:
How do I edit your the code above to add the www. ?
Thanks
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
- jennyhannb
- Posts: 1
- Joined: 22 Dec 2017, 03:23
Re: Simple help needed
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
http://happywheels24.com --> https://happywheels24.com
Re: Simple help needed
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.
Re: Simple help needed
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.
#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.
10 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 10 guests