A
A
Alex Ivanov2017-01-31 17:49:50
htaccess
Alex Ivanov, 2017-01-31 17:49:50

How to make an exception in htaccess for https?

I am migrating a working site to the https protocol, but since the site is old, it does not work out to make it completely on https due to insecure content. There are pages like .../page/text.html in the urls, but there is no such folder physically - this is the htaccess rule that makes such a path. It turns out this code:

RewriteEngine On
RewriteBase /
RewriteRule ^page/(.*)$ page_redir.php?url=$1 [L]

RewriteCond %{REQUEST_URI}  !^/page/.*$
RewriteCond %{HTTP_HOST} ^mysite\.com [NC]
RewriteCond %{HTTP:X-Forwarded-Proto} ^http$
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

But it doesn't work - instead it goes to the url mysite.com/page_redir.php?url=....... and with the https protocol. Please advise how to get out of this situation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Viktor Taran, 2017-03-28
@Protossan

RewriteCond %{HTTP_HOST} ^(www\.|)mysite\.com [NC] - so it will be more accurate.
- everything is correct here as an option, remove the extra space before ! and make a softer condition, will it work?
Also, do not forget that html is, in theory, static, and can be picked up immediately by nginx and not reach the redirect in Apache in principle. Here you need more details about the server conf.
And also the whole .htaccess
and why do you needRewriteCond %{HTTP:X-Forwarded-Proto} ^http$

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question