I have following vhost redirecting 80 to 443:

<VirtualHost *:80>
        ServerName site.mydomain.com
        ServerAlias www.site.mydomain.com
        DocumentRoot /srv/htdocs
        Redirect permanent / https://site.mydomain.com

        <Directory /srv/htdocs>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride None
                Order allow,deny
                allow from all


The problem is that it does not prevent to redirect to other sites, e.g. by:



Which rewrite rule would fix such issue?


Does this solve your issue ?

RedirectMatch "^/$" "https://site.mydomain.com"

It should replace your Redirect... line

RedirectMatch will redirect http://site.mydomain.com to https://site.mydomain.com, but not http://site.mydomain.com/about. In order to achieve the latter, you can use following rewrite rule (again, in place of your Redirect line):

RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]

Add a the trailing / to your redirect URL:

Redirect permanent / https://site.mydomain.com/

Without it, e.g. http://site.mydomain.com/@google.com/ gets redirected to https://site.mydomain.com@google.com/ where the / is missing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.