Domain – Apache Virtual Host redirect from https subdomain to subdirectory

apache-2.4domainredirectsubdomainvirtualhost

How do I redirect requests coming to https://blog.example.com to https://example.com/blog?

Reading the apache docs on when not to use the rewrite mod, I tried a simple redirect e.g.

Redirect https://blog.example.com https://example.com/blog

But when I visit https://blog.example.com, it doesn't redirect me. Only says error with a certificate. Is there any possibility to redirect HTTPS subdomain? It is working ok with HTTP when I use something like this:

<VirtualHost *:80>
    ServerName blog.example.com
    Redirect / https://example.com/blog/
</VirtualHost>

Conditions like these:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^\.]+)\.example\.com$
RewriteRule ^/(.*)$ https://example.com/%1/$1 [R=301,L]

Only work when using HTTP not HTTPS…

Thank you.

Best Answer

Your config applies to VirtualHost *:80, in other words to the http port. The port for https is 443. Find that configuration and apply the redirect there, too.

Related Topic