Htaccess redirect subdomain to subdirectory

I have a multi-level one with drupal, I created a site that first has to be accessible in several ways (subdomains and paths), but now I want to save only one of them; so I would redirect everyone else. Right now I have:

aaa.domain.com/
bbb.domain.com/
domain.com/aaa/
domain.com/bbb/
www.domain.com/aaa/
www.domain.com/bbb/

And I want to redirect all of them to http://www.domain.com/bbb/

I tried to write:

RewriteCond %{HTTP_HOST} ^aaa.domain.com$ [OR]<BR> RewriteCond %{HTTP_HOST} ^bbb.domain.com$ [OR]<BR> RewriteCond %{HTTP_HOST} ^www.domain.com\/aaa$ [OR]<BR> RewriteRule ^/?$ "http\:\/\/www\.domain\.com\/bbb\/" [R=302,L] 

I will use 302 and not 301 until it works as expected.
If I log in to aaa.domain.com, it works as expected, but if I log in
http://aaa.domain.com/page/1
he does not work

I read everything I can about htaccess, but something is missing for me.

thanks

+4
source share
1 answer

Add the file to your .htaccess file to the root of your domain.com site.

 RewriteEngine On RewriteBase / #if request is not on www.domain.com RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC] #and it is not for a folder starting with /bbb/ RewriteCond %{REQUEST_URI} !^/bbb/ [NC] #redirect to www.domain.com/bbb/ RewriteRule .* http://www.domain.com/bbb/ [L,R=301] 
+5
source

Source: https://habr.com/ru/post/1386313/


All Articles