• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Resolved rewrite URL

Seba

Basic Pleskian
I need to rewrite and secure a URL through Plesk or via Command line.

I'm using this code to accept incoming traffic from Clientdomain.gov.uk that doesn't exist anywhere, it's created just on the Registar and it point to our server IP with an A record, in our server we have a domain that it calls myServerdomain.uk

Code:
ServerAlias www.Clientdomain.gov.uk Clientdomain.gov.uk
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(w{3}\.)?myServerdomain\.uk [NC]
RewriteRule (.*) http://www.mydomain.gov.uk/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

How can I have the same result but with an SSL certificate of LE?
 
Last edited:
In order to let the SSL tokens pass the rewrite, start the rewrite with something like this:
Code:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/.well-known/acme-challenge [NC]
RewriteRule .* - [L]

then continue with the rest like
Code:
RewriteCond %{HTTP_HOST} ^(w{3}\.)?myServerdomain\.uk [NC]
RewriteRule (.*) http://www.mydomain.gov.uk/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

The first segment will let the traffic to /.well-known/acme-challenge pass so that the SSL token files can be read regardless of other rewrite rules.
 
for some reason of all the 60 websites just one domain have the .well-known folder. though all of them works correctly.

I tried your solution and:

1) it still show the connection as not secure even if it's https.
2) it redirect me to the default domain in the server (it's not pointing to the correct domain)
 
my bad I think, do I need to put it in the https directive isn't?

Even in the https directive I still have the same errors.

I apply the LE certificate without rules and it works perfectly, when I apply the rewrite rules it seems that it doesn't know where to go and it point to the server IP and showing the default domain.

I've applied

Code:
ServerAlias www.Domain.gov.uk Domain.gov.uk

on both HTTP and HTTPS directives and now seems to point to the correct domain, though it complain about the padlock, the website you passed me say that it doesn't match the domain name.

The SSL it's for my serverDomain not for the other subdomain.gov.uk, do I need an SSL for the gov.uk?
 
Last edited:
I finally found a solution, i think that no one has though about it when they checked my code.

you need to add a domain alias, in Apache i was using this

Code:
ServerAlias www.mydomain.gov.uk mydomain.gov.uk

but you can do it in Plesk very easy.

Adding Domain Aliases

now you can install the SSL

How to install a certificate for domain alias

and finally you can prevent the redirect to the domain in the server

How to prevent domain alias url get redirected to main domain url?

in the HTTPS directives I still use the below code as the previous redirect doesn't work in both way, it just prevent the mydomain.gov.uk to be rewritten into myServerdomain.uk
so if you connect to myServerdomain.uk you still will see myServerdomain.uk instead of mydomain.gov.uk but with this code it doesn't matter wich URL you use, the final one displayed in the URL is mydomain.gov.uk

Code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(w{3}\.)?myServerdomain\.uk [NC]
RewriteRule (.*) http://www.mydomain.gov.uk/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
 
Back
Top