Answer the question
In order to leave comments, you need to log in
How to redirect from a subdomain to the main site?
Good afternoon!
Faced such a problem, there is a main site and a subdomain. You need to redirect from the subdomain to the main site only if this is not an authorization page, and not the main page of the subdomain.
Tried to do so
RewriteCond %{HTTP_HOST} sub\.site\.ru [NC]
RewriteCond %{REQUEST_URI} !^/user(.*)$ [NC]
RewriteCond %{REQUEST_URI} !$ [NC]
RewriteRule ^(.*)$ https://site.ru/$1 [L,R=301]
Answer the question
In order to leave comments, you need to log in
Added the rewrite output to the Apache log and in the end it turned out like this
RewriteCond %{HTTP_HOST} ^sub\.site\.ru [NC]
RewriteCond %{REQUEST_URI} !^/user(.*)$ [NC]
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_URI} !^/index.php$
RewriteRule ^(.*)$ https://site.ru/$1 [L,R=301]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question