Apache redirecting https://host:port/folder to http://host:port/folder/

apache-2.2httpsmod-rewrite

I have a apache server using two SSL domains (no SNI support) in different ports, kinda like this:

I have a Rewrite rule to redirect http://host2.tld:80 to :444 (and the same to host1). Then there is the problem:

I have a folder "folder" on host2 root. If I try to access http://host2.tld/folder/, everything is ok and I end up in https://host2.tld:444/folder/ as expected. Now, if I type http://host2.tld/folder, apache redirect me to http://host2.tld:444/folder/, which doesn't exist.

Since the redirection from "folder" to "folder/" is automatically done, what can I do to fix my problem?

Mod-rewrite config:

<VirtualHost *:80>
    ServerName host2.tld
    RewriteEngine On
    RewriteRule (.*) https://%{HTTP_HOST}:444%{REQUEST_URI} [R=301,L]
</VirtualHost>

Best Answer

Remove the L from your rewrite rule. That option indicates that rule is the 'last' rule and no further rewriting will occur.

When you go to http://host2.tld/folder it rewrites the uri to add the slash, but doesn't process any further.

You may also want/need to add a condition to the rewrite in order to prevent a loop on every request.

Related Topic