Apache HTTP RewriteRule for hostname

758 Views Asked by At

everyone.

My problem is simple, but I cannot manage to find a solution.

All I need to do is use RewriteRule on Apache to redirect all request from a hostname to its FQDN.

For example, if the request is https://hostname/test.html, I want Apache to redirect the request to https://hostname.test.com/test.html. This has to be rewritten to any request to that hostname.

How can I do this?

Edit 1:

I've noticed that the following RewriteRule works for HTTP, but not for HTTPS:

RewriteCond %{​​​​​​​HTTP_HOST}​​​​​​​ ^hostname$
RewriteRule ^(.*)$ https://hostname.test.com%{​​​​​​​​REQUEST_URI}​​​​​​​​ [R,L]

What am I missing?

BR

1

There are 1 best solutions below

0
tomasaazevedo On

I've managed to find the problem.

The redirect is working.

The problem is that the certificate does not contain the hostname version of the URL, only the FQDN.

Since the certificate is checked before the redirect, hence the problem.

Sorry for the mess up