Redirect domain to a particular server folder via htaccess

Asked

Viewed 278 times

0

I have two domains that point to my server, both to the public_html root folder. I need each domain to access a certain folder.

Example:

www.dominio1.com.br points to the folder /dominio_1

www.dominio2.com.br points to the folder /dominio_2

I looked for the commands to use in htaccess but without success. I don’t know much about regular expression, someone there has the tricks?

Thanks in advance.

1 answer

2


To perform this task it is necessary to use the Rewritecond

<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{HTTP_HOST} .*dominio1.* [NC]
    RewriteRule ^(.*)$ dominio1.php [L]

    RewriteCond %{HTTP_HOST} .*dominio2.* [NC]
    RewriteRule ^(.*)$ dominio2.php [L]
</IfModule>

Explanation

  • RewriteCond %{HTTP_HOST} - Says you want to check something in the domain
  • .*dominio1.* - This checking whether the domain has the sentence
  • [NC] - No case - You mean case insensitive.

If the sentence is confirmed, similar to a if performs the RewriteRule that is below.

Browser other questions tagged

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