lhoupert
lhoupert

Reputation: 704

Using htaccess to redirect multiple domains with subdomains http[s] [www] to a https://[subdomains].domain3

I am trying to redirect:

http://www.[subdomains.]thedomain.ml
http://[subdomains.]thedomain.ml
https://www.[subdomains.]thedomain.ml
https://[subdomains.]thedomain.ml

http://www.[subdomains.]ledomain.ml
http://[subdomains.]ledomain.ml
https://www.[subdomains.]ledomain.ml
https://[subdomains.]ledomain.ml

to

https://[subdomains.]domain3.fr

where the value of [subdomains.] is not known and can take multiple values.

I browsed stackoverflow posts a lot but I couldn't find a solution which also includes subdomains into the redirection.

My current .htaccess file is below but doesn't include subdomains

SetEnv PHP_VER 5_4
Options -Indexes
Options +FollowSymLinks
RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^domain3\.fr$ [NC]
RewriteRule ^ https://domain3.fr%{REQUEST_URI} [R=301,L,NE]


<Files .htaccess>
order allow,deny
deny from all
</Files>


Thank you

Upvotes: 1

Views: 36

Answers (1)

RavinderSingh13
RavinderSingh13

Reputation: 133760

With your shown samples, could you please try following. Please make sure you clear your browser cache before testing URLs.

SetEnv PHP_VER 5_4
Options -Indexes
Options +FollowSymLinks

RewriteEngine ON
RewriteCond %{HTTP_HOST} ^(?:www\.)?(?:[\w-]+\.)?([\w-]+)\.ml$ [NC]
RewriteRule ^ https://%1.fr%{REQUEST_URI} [R=301,L,NE]

Upvotes: 1

Related Questions