Set directory to subdomain via HTACCESS

Asked

Viewed 187 times

1

I created a sub-domain and would like its directory to be a specific folder.

For example:

Sub-domain: test.site.com.br

Briefcase: website/folder/

Here’s what I tried:

RewriteCond %{HTTP_HOST} ^teste.site.com.br$
RewriteRule ^(/)?$ pasta/ [L]
  • You can set this in the apache itself, but I will reply with a possible that suited your case, see and it works.

1 answer

1


Follows the possible solution.

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^teste.site.com.br$
    RewriteRule ^(.*)$ pasta/$1 [L]
</IfModule>

Test it and tell me, if it works for your case.

But in advance I’ll leave the sites-enabled from the apache to you here:

"Access the directory /etc/apache2/sites-enabled/ create a file with your domain name finished by .conf except: abcd.com.br.conf, I usually already have a model ready here and I will use it as an example."

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin [email protected]
    DocumentRoot /var/www/AdmMedico/public
    ServerName  pinheiro.com.br
    ServerAlias www.pinheiro.com.br

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
<Directory "/var/www/pinheiro/public">
    AllowOverride All
</Directory>

</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Reference :Deploy Laravel application

  • I tested your htaccess code, but an error appeared: https://i.imgur.com/vBjvczC.png &#Xa...

  • This is ssl error, your site has https ? may be that the certificate is only for the main domain. tries to access as http:// (i don’t if you really have https. if yes see with the hosting the certificate)

  • 1

    Yes, every time a directory is created it is a birth. It’s a cyber security company where they block pretty much everything there every time you have to contact them so they go giving them little permissions until it works out. But I believe this code is correct, because I put the subdomain/ a directory that does not exist and gave different error. As soon as they release me I confirm the answer, I believe I’m correct...

  • @Lucas Blz, they certainly work with restrictive rules, if it doesn’t work comment on the error here that we align until it gets right.

  • you who knows more: the problem really is in https, I took the direction of htaccess and the site at least showed, however error 404 (that is, it is not seeking the correct directory), but my doubt, can be senseless: I direct everything to https, but I would like to direct only this sub-domain to http, you can do this?

  • Take a look at this https://answall.com/questions/364158/redirecinamento-301-htaccess-com-e-sem-www-para-https/364160#364160 it and take part of https. in case remove the redirect the directory, and test, if it really works the problem is in the way, watch out for if it will put the complete directory.

Show 1 more comment

Browser other questions tagged

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