PDA

View Full Version : Windows Server https:// redirect


RichieBoy67
01-25-2017, 08:02 PM
I have the code below to redirect to https://www using web.config. Is this correct?

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<clear />
<rule name="Redirect to https" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://www{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>

Also, how do I add this to the config? It already has <handlers></handlers>.. I just paste it in there above <system.webServer>
Thanks,
Rich

AWS
01-26-2017, 10:13 AM
You have a couple errors.


<rule name="http to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="^OFF$" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
</rule>


Set canonical domain for www like this.


<rule name="CanonicalHostNameRule1">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^www\.yourdomain\.com$" negate="true" />
</conditions>
<action type="Redirect" url="http://www.yourdomain.com/{R:1}" />
</rule>

Dr.CustUmz
01-29-2017, 10:36 AM
try my product =)
https://vborg.vbsupport.ru/showthread.php?t=322433

Stratis
01-29-2017, 12:28 PM
try my product =)
https://vborg.vbsupport.ru/showthread.php?t=322433

Ryan, does it work in vb4.2xx ?
Thanks

Dr.CustUmz
01-29-2017, 09:05 PM
there's no reason it shouldn't give it a shot and let me know, there are no settings for it. it is simply a plugin at the init_startup hook redirecting from http to https, if you do not already have https set up prior to installing it will not work.

if(empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "off"){
$redirect = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
header('HTTP/1.1 301 Moved Permanently');
header('Location: ' . $redirect);

DivisionByZero
01-30-2017, 06:30 PM
redirects should ALWAYS be done at the server level!

RichieBoy67
01-30-2017, 06:32 PM
redirects should ALWAYS be done at the server level!
#1 - I only have access to the forum and forum directory, not the root

#2 - Only the forum needs to be switched to https://

DivisionByZero
01-30-2017, 06:34 PM
.htaccess or web.config suffices as server-level config, per-directory too.

RichieBoy67
01-30-2017, 06:37 PM
Thanks, but I know this much already. lol That is what I was trying to figure out. How to do the https:// in the web.config.. I think I got it now anyways but thanks much.

DivisionByZero
01-30-2017, 06:38 PM
ok. let me know if it doesn't work. i use windows server myself and have it setup somewhere.

Stratis
02-06-2017, 06:29 AM
Does any one have solution for both redirect in .htaccess ?

http to https
non www to www

with 301

Thanks

RichieBoy67
02-10-2017, 02:22 PM
Does any one have solution for both redirect in .htaccess ?


http to https
non www to www

with 301

Thanks
I use this:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]