Nginx

server {
listen 80;
listen [::]:80;

server_name .example.com;


location / {
return 301 https://example.com $request_uri;
}
}


Apache


RewriteCond %{HTTPS} =on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /(.*)//(.*) HTTP/ [NC]
RewriteRule ^.*$ https://%{SERVER_NAME}/%1/%2 [R=301,L]