Directing subdomain (htaccess) to Codeigniter

Asked

Viewed 363 times

2

I’m having a problem that’s giving me a headache..

I own a domain, and then from it I generated a subdomain. This subdomain is inside my public_html, so I can access by placing /nameserver

However, he wanted it to be part of subdomain.. for example www.subdominio.dominio.com.br

I tried about 20 different . htaccess types, but I couldn’t make it work. Can anyone help me? Thanks

  • You have access to Apache configuration files?

  • unfortunately not.. using the Hostinger s;

  • 1
  • I still couldn’t make it work..

  • sometimes even directs to the sub-domain, but ends up not taking the files from the directory..

  • I have a project in codeigniter, within public_html, with an htacces for him.. and I have in this folder public_html another folder, which is another project all with the imports of code Igniter and a new . htaccess, this is what may give problem will be?

  • I know how to do this only by editing the Apache configuration files, as you use the Hostinger hosting advise to contact them. The support boys are very attentive, it’s worth a try.

Show 2 more comments

1 answer

0

You need to go to your DNS configuration (cloudflare, register.br, godaddy, dynadot) and add an alias to your subdomain within the existing domain DNS configuration.

Also, within the vhost configuration of your existing web server (apache, Nginx lighttpd and others), there should be an entry pointed root to the subdomain folder, usually this is created by Cpanel among other managers automatically.

This is a classic example of vhost from Nginx listening on port 80 which is the browser one. Note that the domain root folder is /var/www/html and that this template will be executed when there is a request that meets the defined server_names, in this case, www.meudominio.com and meudominio.with. Therefore the same vhost structure for your new subdomain (Subdomain.meudominio.com) pointing to your root folder should also exist on the server. Despite the different syntax the procedure is the same for apache and too.

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;
    index index.html index.htm index.nginx-debian.html;

    server_name www.meudominio.com meudominio.com;

    location / {
            try_files $uri $uri/ =404;
    }
}

For example let’s say your domain is meudominio.with and you want to open the domain Domain.meudominio.com

Within the DNS settings you will see entries with these :

A meudominio.com  158.69.20.14 
A www             158.69.20.14  

That is www is a subdomain of meudominio.com and points to the ip of your server, in this case if we want to add a new subdomain, just add a new alias to your DNS, so:

A meudominio.com  158.69.20.14 
A www             158.69.20.14  
A subdominio      158.69.20.14  

Saying that there is an alias (A) subdomain, which points to the ip of this machine as well or even using another server with a different ip. When someone makes a request by Domain.meudominio.com DNS resolution will forward the request to the ip pointed in your DNS record, arriving at the target server, the web server locates the vhost template with the requested server_name and meets the request by pointing to the internal folder defined in the root of your vhost file. Usually adding subdomains to your DNS does not require waiting time, since the main domain has already been propagated over the network.

Browser other questions tagged

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