Y
Y
yoursmileua2015-11-23 19:26:13
CodeIgniter
yoursmileua, 2015-11-23 19:26:13

How to redirect a function to a subdomain in codeigniter?

Hello everyone
There is an address of this type that opens the user's page:
infoumnik.local/user_site/sub/user2
How to make the user's page open at this address?
http:// user2 .infoumnik.local/ Figured out
only how to make a folder

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.infoumnik\.local$
RewriteCond %{HTTP_HOST} (www\.)?(.*)\.infoumnik\.local$
RewriteCond %{REQUEST_URI} !user_site/sub/
RewriteRule ^(.*)$ user_site/sub/%2/$1

Thanks for the help!!!!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
G
Grigory Vasilkov, 2015-11-23
@gzhegow

No way - you need a domain name, copy another codeigniter there, and make a controller and an action there, which will pull another one from the same base.
Or to cheat already with a server so that it requests you a file on a subdomain that lies in a completely different directory from the root one. I doubt that this is done by a simple redirect, because your htacess is responsible for the current folder, and you are at war with domain names.
The idea that is the simplest but stupid is to request a page on a subdomain with some kind of file_get_contents, but it will be damn inconvenient to work with this.

Y
yoursmileua, 2015-11-23
@yoursmileua

Alternatively, you can do something like this

$subdomain_arr = explode('.', $_SERVER['HTTP_HOST'], 2); 
        $subdomain_name = $subdomain_arr[0]; 
        $this->db->from('user_site')->where('subdomain_name', $subdomain_name);
        $query = $this->db->get();
        
        $subdomain_info = $query->row();        
        if($query->num_rows() < 1)
        {
            redirect('blog');
        } //иначе открываем вид

That is, what I wanted to write with this. First, we find out the subdomain using explode and if it is in the database, then we open the view for this subdomain.
If it is not in the database, then redirect to any page.
Initially, if you write
user1.infoumnik.local
user2.infoumnik.local
user3.infoumnik.local
, etc. it simply opens a page that is equal to infoumnik.local, i.e. as if there is no subdomain.
My code above will essentially work in a similar way, only it will load the view and substitute it into the address, for example, user2.infoumnik.local.
But the downside is that you have to check this in each function, and this is a lot of requests.
What do you think? Didn't I mess up anything?

E
evnuh, 2015-11-23
@evnuh

1) In dns, make sure that there is an A record for subdomains
2) make a wildcard virtual server *.infoumnik.local in your web server that looks at the folder with the current site
3) Do an internal rewrite in the web server config with * (except www) at infoumnik.local/user_site/sub/*

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question