Redirect for http > https & domain > www.domain Not Working

ISAPI_Rewrite is Apache mod_rewrite compatible URL rewriter for Microsoft IIS
User avatar
Posts: 5
Joined: 17 Sep 2015, 09:16

Redirect for http > https & domain > www.domain Not Working

17 Sep 2015, 10:13

Hi,

we are using Helicon ape 3.1.0.48 on IIS 8.5 / windows server 2012 R2.

We are using the following redirects in the .htaccess, via Helicon Ape Manager.

We want it to also redirect for case 2, but I can't work out how to do that. Everything I try fails.

Any ideas? :)

1 http domaincom > https www domain com works!
2 http www domain com > https www domain com DOES NOT WORK!
3 https domain.com > https www domain com works!
4 https www.domain.com > https www domain com works!



using

RewriteEngine On
RewriteBase

#Fix missing trailing slash char on folders
RewriteRule ^([^.?]+[^.?/])$ $1/ [R,L]

RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^104.130.159.140$ [NC]
RewriteCond %{REQUEST_URI} !^/(blog)(/|$)
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) https://www.domain.com/$1 [L,R]

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: Redirect for http > https & domain > www.domain Not Work

17 Sep 2015, 16:22

Hello,

It would be easier and more logical to separate it in 2 rules:

RewriteEngine On
RewriteBase

#Fix missing trailing slash char on folders
RewriteRule ^([^.?]+[^.?/])$ $1/ [R,L]

RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^104.130.159.140$ [NC]
RewriteCond %{REQUEST_URI} !^/(blog)(/|$)
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) https://www.domain.com/$1 [L,R]

RewriteCond %{HTTPS} ^(?!.*on.*).*
RewriteRule ^/(.*) https://www.domain.com/$1 [L,R]

User avatar
Posts: 5
Joined: 17 Sep 2015, 09:16

Re: Redirect for http > https & domain > www.domain Not Work

18 Sep 2015, 14:17

yes, i tried two rules, and also your exact code using about domain, but it then enters into a redirect loop.

the full htaccess is this:

# Helicon Ape version 3.1.0.148
RewriteEngine On
RewriteBase

### FILTER OUT KNOWN BAD REQUESTS
RewriteRule ^/images/(bullets|footer|header|specials|tabs|titles|tools|wallpaper)/(.*)$ /sitemap.cfm [G]
RewriteRule ^/_vti_bin/(.*)$ /sitemap.cfm [G]
RewriteRule ^/awmData-(.*)$ /sitemap.cfm [G]
RewriteRule ^/awmmenupath.gif$ /sitemap.cfm [G]
### END BAD KNOWN REQUEST FILTER


### FORCE ALL TRAFFIC THROUGH THE PRIMARY DOMAIN
#Fix missing trailing slash char on folders
RewriteRule ^([^.?]+[^.?/])$ $1/ [R,L]

RewriteCond %{HTTP_HOST} !^www\.domainname\.com$ [NC]
RewriteCond %{HTTP_HOST} !^104.130.159.140$ [NC]
RewriteCond %{REQUEST_URI} !^/(blog)(/|$)
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) https://www.domainname.com/$1 [L,R=301]


### 3D ISSUE REWRITE - THIS MUST BE BEFORE THE PAGE FLIP CONTENT SINCE THAT RULE IS MORE GENERIC
RewriteRule ^/pub/.*/sendtofriend\.(asp|php)$ /pub/sendtofriend.cfm [NC,L,U]

RewriteRule ^/view/brochure/09162015/pub/.*/sendtofriend\.(asp|php)$ /pub/sendtofriend.cfm [NC,L,U]

RewriteRule ^/view/brochure/09172015/pub/.*/sendtofriend\.(asp|php)$ /pub/sendtofriend.cfm [NC,L,U]

RewriteRule ^/view/brochure/09182015/pub/.*/sendtofriend\.(asp|php)$ /pub/sendtofriend.cfm [NC,L,U]

RewriteRule ^/view/brochure/09192015/pub/.*/sendtofriend\.(asp|php)$ /pub/sendtofriend.cfm [NC,L,U]

RewriteRule ^/view/brochure/09202015/pub/.*/sendtofriend\.(asp|php)$ /pub/sendtofriend.cfm [NC,L,U]

RewriteRule ^/view/brochure/09212015/pub/.*/sendtofriend\.(asp|php)$ /pub/sendtofriend.cfm [NC,L,U]

RewriteRule ^/view/brochure/09222015/pub/.*/sendtofriend\.(asp|php)$ /pub/sendtofriend.cfm [NC,L,U]

RewriteRule ^/view/brochure/09232015/pub/.*/sendtofriend\.(asp|php)$ /pub/sendtofriend.cfm [NC,L,U]

RewriteRule ^/view/brochure/09242015/pub/.*/sendtofriend\.(asp|php)$ /pub/sendtofriend.cfm [NC,L,U]

RewriteRule ^/view/brochure/09252015/pub/.*/sendtofriend\.(asp|php)$ /pub/sendtofriend.cfm [NC,L,U]

### END 3D ISSUE REWRITE

### BEGIN PDF CONTENT
RewriteRule ^/downloads/brochures/09162015/(.*)$ /pdf/$1 [NC,L,U]

RewriteRule ^/downloads/brochures/09172015/(.*)$ /pdf/$1 [NC,L,U]

RewriteRule ^/downloads/brochures/09182015/(.*)$ /pdf/$1 [NC,L,U]

RewriteRule ^/downloads/brochures/09192015/(.*)$ /pdf/$1 [NC,L,U]

RewriteRule ^/downloads/brochures/09202015/(.*)$ /pdf/$1 [NC,L,U]

RewriteRule ^/downloads/brochures/09212015/(.*)$ /pdf/$1 [NC,L,U]

RewriteRule ^/downloads/brochures/09222015/(.*)$ /pdf/$1 [NC,L,U]

RewriteRule ^/downloads/brochures/09232015/(.*)$ /pdf/$1 [NC,L,U]

RewriteRule ^/downloads/brochures/09242015/(.*)$ /pdf/$1 [NC,L,U]

RewriteRule ^/downloads/brochures/09252015/(.*)$ /pdf/$1 [NC,L,U]
### END PDF CONTENT

### BEGIN PAGE FLIP CONTENT
RewriteRule ^/view/brochure/09162015/(.*)$ /$1 [NC,L,U]

RewriteRule ^/view/brochure/09172015/(.*)$ /$1 [NC,L,U]

RewriteRule ^/view/brochure/09182015/(.*)$ /$1 [NC,L,U]

RewriteRule ^/view/brochure/09192015/(.*)$ /$1 [NC,L,U]

RewriteRule ^/view/brochure/09202015/(.*)$ /$1 [NC,L,U]

RewriteRule ^/view/brochure/09212015/(.*)$ /$1 [NC,L,U]

RewriteRule ^/view/brochure/09222015/(.*)$ /$1 [NC,L,U]

RewriteRule ^/view/brochure/09232015/(.*)$ /$1 [NC,L,U]

RewriteRule ^/view/brochure/09242015/(.*)$ /$1 [NC,L,U]

RewriteRule ^/view/brochure/09252015/(.*)$ /$1 [NC,L,U]
### END PAGE FLIP CONTENT

### BEGIN PAGE CONTENT
RewriteRule ^/travel(?:/[^/]+)*/trip/([^/]+)/([^/]+)(?:/([^/]+))?(?:/([^/]+))?(?:/([^/]+))?(?:/([^/]+))?(?:/([^/]+))?(?:/([^/]+))?(?:/([^/]+))?(?:/([^/]+))?(?:/([^/]+))?(?:/([^/]+))?(?:/([^/]+))?(?:/([^/]+))?(?:/([^/]+))?(?:/([^/]+))?(?:/([^/]+))?(?:/([^/]+))?(?:/([^/]+))?(?:/([^/]+))?.*$ /index.cfm\?$1=$2&$3=$4&$5=$6&$7=$8&$9=$10&$11=$12&$13=$14&$15=$16&$17=$18&$19=$20 [NC,L,U]
### END PAGE CONTENT


### REDIRECT ALL /PRESS REQUESTS TO /NEWS
RewriteRule ^/press/(.*)$ /news/$1 [R=301,L]

RewriteRule ^/trip_logs(.*)$ /blog/category/trip-logs/$1 [R=301,L]

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: Redirect for http > https & domain > www.domain Not Work

21 Sep 2015, 07:26

Please try using NS flags after redirect rules to avoid loops:

RewriteRule ^/(.*) https://www.domainname.com/$1 [L,R=301,NS]

RewriteRule ^/press/(.*)$ /news/$1 [R=301,L,NS]

RewriteRule ^/trip_logs(.*)$ /blog/category/trip-logs/$1 [R=301,L,NS]

If it doesn't help, please enable logging in httpd.conf by putting

RewriteLogLevel 9

and provide rewrite.log records for your test request in question.

User avatar
Posts: 5
Joined: 17 Sep 2015, 09:16

Re: Redirect for http > https & domain > www.domain Not Work

21 Sep 2015, 13:06

didn't work I'm afraid.

I added NS to all RewriteRule and it created a loop and timeout,
adding to just the www/https rewrites didn't seem to change behaviour.

I added RewriteLogLevel 9 to the htaccess via helicon ape, also did an iisreset, not not content is being added to the two rewrite.log files i can find.
C:\Program Files (x86)\Helicon\Ape\rewrite.log
C:\Program Files (x86)\Helicon\Ape\ManualInstall\rewrite.log


We're on IIS not apache, btw.

currently:
RewriteRule ^([^.?]+[^.?/])$ $1/ [R,L]

RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^104.130.159.140$ [NC]
RewriteCond %{REQUEST_URI} !^/(blog)(/|$)
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) https://www.domain.com/$1 [L,R=301,NS]

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: Redirect for http > https & domain > www.domain Not Work

21 Sep 2015, 20:00

Hello,

>We're on IIS not apache, btw.

Sure thing - otherwise you wouldn't need Ape :)

>I added NS to all RewriteRule and it created a loop and timeout

You should add NS only to redirect rules (the ones with R or R=301 flags).

And let me try fix the rules again:

RewriteEngine On
RewriteBase

#Fix missing trailing slash char on folders
RewriteRule ^([^.?]+[^.?/])$ $1/ [R,L]

RewriteCond %{HTTPS} ^(?!.*off.*).*
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^104\.130\.159\.140$ [NC]
RewriteCond %{REQUEST_URI} !^/blog/?$
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) https://www.domain.com/$1 [L,R=301,NS]

RewriteCond %{HTTPS} ^(?!.*on.*).*
RewriteCond %{HTTP_HOST} ^(?:www\.)?domain\.com$ [NC]
RewriteRule ^/(.*) https://www.domain.com/$1 [L,R=301,NS]

User avatar
Posts: 5
Joined: 17 Sep 2015, 09:16

Re: Redirect for http > https & domain > www.domain Not Work

22 Sep 2015, 11:43

thanks, I checked those RewriteRules, only have NS for R flags

unfortunately that code creates a loop: (in firefox)

This web page has a redirect loop

ERR_TOO_MANY_REDIRECTS



Interestingly, the current code below works, rewriting urls to https://wwww in all cases.. but not in Firefox or Chrome, where it doesn't rewrite www.domain.com to https

RewriteRule ^([^.?]+[^.?/])$ $1/ [R,L,NS]

RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^104.130.159.140$ [NC]
RewriteCond %{REQUEST_URI} !^/(blog)(/|$)
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) https://www.domain.com/$1 [L,R=301,NS]

User avatar
Posts: 5
Joined: 17 Sep 2015, 09:16

Re: Redirect for http > https & domain > www.domain Not Work

22 Sep 2015, 12:38

could this issue be because, as per attached image, FF and Chrome don't like redirecting to a url which isn't entirely secure, so ignores a rewrite to https? where as IE doesn't seem to care?
Attachments
secureBrowser2.png
secureBrowser2.png (27.16 KiB) Viewed 6201 times

User avatar
Posts: 871
Joined: 12 Mar 2012, 09:54

Re: Redirect for http > https & domain > www.domain Not Work

23 Sep 2015, 00:59

Hello,

>could this issue be because, as per attached image, FF and Chrome don't like redirecting to a url which isn't entirely secure, so ignores a rewrite to https?

This could definitely be the issue.
To make sure, it would be great to see rewrite.log which you didn't manage to get.
Can you check the IIS log to see what is the status code the this looping test request.

Return to ISAPI_Rewrite 3.0

Who is online

Users browsing this forum: No registered users and 17 guests