1

We are trying to redirect requests on port 8555 to port 8443. In our httpd.conf file, we have the following:

<VirtualHost *:8555>
SSLEngine on
# SSL configuration that is irrelevant to this question

RewriteEngine on
RewriteRule ^(.*)$ https://%{HTTP_HOST}:8443%{REQUEST_URI}
</VirtualHost>

However, when a user goes to https://example.con:8555/foo, they get redirected to https://example.com:8555:8443/foo instead of https://example.com:8443/foo. How do I correct this?

1 Answer 1

2

HTTP_HOST contains the value set by the "Host:" request header. You could try using SERVER_NAME instead, which contains the value of the ServerName directive, if configured in your VirtualHost block. Otherwise httpd tries to find the ServerName via reverse DNS.

RewriteRule ^(.*)$ https://%{SERVER_NAME}:8443%{REQUEST_URI}

Another option, if you only have one server name you can just write it in the RewriteRule directly, you don't have to use variables for this.

RewriteRule ^(.*)$ https://example.com:8443%{REQUEST_URI}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .