0

I had an issue with website redirection and I found that my rewritecond input= 'www.example.com' and my request header host = 'example.com'. So I try to apply UseCanonimalName On in vhost where my ServerName define as 'www.example.com' by hoping that when both are matched, my website redirection will happen but unfortunately it doesn't and host in my request header still remain 'example.com'. I refer to this and this to do it.

Below are my httpd-vhost.conf:

<VirtualHost *:80>
    ServerName www.example.com
    ServerAlias example.com
    UseCanonicalName On
    DocumentRoot "d:/wamp64/www/example"
    <Directory  "d:/wamp64/www/example/">
        Options +Indexes +Includes +FollowSymLinks +MultiViews
        AllowOverride All
        Order allow,deny
        Allow from all
        Header always set Strict-Transport-Security "max-age=63072000; includeSubDomains"
    </Directory>
</VirtualHost>

Below are the host that I got enter image description here

Below are the expectation that I would want to receive: enter image description here

The host is changing from example.com to www.example.com but unfortunately, it only works in Firefox but not other browsers which IDK why?!

***Am using Windows server

Please correct me if I understand or do it wrongly. Thanks all!

Petri
  • 37
  • 9

1 Answers1

1

The UseCanonicalName is not related to redirections but to self-referential URLs.

  • Off: "form self-referential URLs using the hostname and port supplied by the client"
  • On: "use the hostname and port specified in the ServerName directive to"

The redirection you see is not related to this, but a result of the HSTS policy you have specified with Strict-Transport-Security. A browser that supports HSTS and has seen this header will perform an internal redirection to HTTPS regardless your <VirtualHost *:80> configuration.

Esa Jokinen
  • 43,252
  • 2
  • 75
  • 122
  • I just refer to this https://superuser.com/questions/1187875/can-i-put-just-the-hostname-as-servername-in-apache-virtualhost-directive where ezra comment that browser sends a specific request header called "Host" and it is defined in ServerName. So it means the "host" should be the host of actual live site am I right? Let say the host of my actual live site is www.example.com, my ServerName should also name as www.example.com, right? – Petri Apr 24 '20 at 07:11