S
S
Sergey Pozdnyakov2016-10-06 14:36:30
Apache HTTP Server
Sergey Pozdnyakov, 2016-10-06 14:36:30

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]

When you need to catch subfolders, everything is fine, but how to make it "not the root of a subdomain"?
Tried !^/$ doesn't work either. In the variant as described above, the redirect does not occur at all.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Pozdnyakov, 2016-10-06
@Afinogen

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]

Website on ZF2

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question