Redirect to https:// partially working

Hi all,
First I’ve installed cert bot for mysite.net. Then I’ve added www.mysite.net to the cerificate.

The rewrite rule for mysite.net, added by certbot worked and still working now.
But not the rewrite rule for www.mysite.net added by me.

What is wrong??

I’ve tried to modify the rewrite rule on 000-default.conf configuration as follow:

RewriteEngine on
RewriteCond %{SERVER_NAME} =mysite.net [OR]
RewriteCond %{SERVER_NAME} =www.mysite.net
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [L,QSA,R=permanent]

In 000-default-le-ssl.conf I’ve also added:

ServerAlias mysite.net *.mysite.net

This is the server name as defined by the Apache configuration, not the hostname of the incoming request.

Maybe try matching against HTTP_HOST instead.

2 Likes

I’ve tried with HTTP_HOST, but with the same results.

RewriteEngine on
RewriteCond %{HTTP_HOST} =effegiweb.net [OR]
RewriteCond %{HTTP_HOST} =www.effegiweb.net
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,QSA,R=permanent]

I need to study mod_rewrite rule!!
:frowning:

I have never seen that = syntax before. Does it work if you remove that symbol from the RewriteCond lines?

Since this file was generated by Certbot anyway, maybe we should take the approach that Certbot should actually generate these rules correctly by itself. Any thoughts @schoen ?

Edit: actually, nevermind. The redirect seems to work fine for me, but does not seem the correlate with the above config section:

$ curl -I www.effegiweb.net
HTTP/1.1 301 Moved Permanently
Date: Tue, 27 Feb 2018 22:45:13 GMT
Server: Apache/2.4.18 (Ubuntu)
Location: https://www.effegiweb.net/
Content-Type: text/html; charset=iso-8859-1

$ curl -I effegiweb.net
HTTP/1.1 301 Moved Permanently
Date: Tue, 27 Feb 2018 22:45:29 GMT
Server: Apache/2.4.18 (Ubuntu)
Location: https://effegiweb.net/
Content-Type: text/html; charset=iso-8859-1
1 Like

Ok, Let’s work!
I’ve tried too with curl -I and using a different browser.
But with the previous browser still not work for www …
I’m not sure that SERVER_NAME could be the problem, at this point I think that the browser cache have joked me!

This is valid. It is for string comparison instead of a regular expession match.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.