How do I force . htaccess to direct a domain into a folder?

Asked

Viewed 535 times

1

I don’t understand much of it. htaccess from apache, so I would like to ask colleagues if it is possible what I am going to explain, I have a domain: mycard.com.br and a domain test.mycard.com.br the domain folder is /home/mycard/html already the domain folder is /home/mycard/html/subdominios/test.

I wanted the user not to enter the Domain by the link http://mycard.com.br/subdominios/teste rather than by http://teste.mycard.com.br

If he types: http://mycard.com.br/subdominios or http://mycard.com.br/subdominios/teste

I could put a redirect file in those folders, but if it type http://mycard.com.br/subdominios/teste/index.php he accesses and that I didn’t want

He would be redirected to http://teste.mycard.com.br

It is possible to do this by . htaccess?

The ideal would be to create the subdominios on the same level as the html folder, but I don’t have access to the apache vhosts the Locaweb server creates the subdominios folder inside html

  • And where will you redirect if he type http://mycard.com.br/subdominios?

  • http://mycard.com.br

  • and if it type http://mycard.com.br/subdominios/test it must go to http://teste.mycard.com.br

  • In addition, the subdomain http://mycard.com.br/subdominios/foo have to redirect to foo.mycard.com.br or teste.mycard.com.br?

  • This, if it is the subdominios folder it should go to the main site http://mycard.com.br and if it is a subfolder it should go to http://foo.mycard.com.br

1 answer

1


RewriteEngine On

# http://mycard.com.br/subdominios  -->  http://mycard.com.br
RewriteCond %{HTTP_HOST} ^mycard\.com\.br$ [NC]
RewriteRule ^subdominios/?$ / [R=301,NC,L]

# http://mycard.com.br/subdominios/nome  -->  http://nome.mycard.com.br
# http://mycard.com.br/subdominios/nome/exemplo.html  -->  http://nome.mycard.com.br/exemplo.html
RewriteCond %{HTTP_HOST} ^mycard\.com\.br$ [NC]
RewriteRule ^subdominios/([^/]+)(/.*)? http://$1.mycard.com.br$2 [R=302,NC,L]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.