Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi Domains for Codeiginiter

hi we have a project on codeigniter PHP in my controller have two folder

  • member
  • admin

i am access to these folder like this

http://example.com/member
http://example.com/admin

but i want not anyone access like above domain to these folder if any one access like above domain its show a 404 error page

i want anyone access these folder to help of subdomain like

http://member.example.com
http://admin.example.com

my question is how to create sub domain for different folder in codeigniter folder and how to show error 404 page for above question

like image 312
Sameed Alam Qureshi Avatar asked Aug 04 '26 05:08

Sameed Alam Qureshi


1 Answers

One way to achieve this would be using wildcard subdomains as @Sagar Khatri mentioned or specific subdomains and HTACCESS.

You create your subdomains: member.site.com & [email protected]

Now using HTACCESS file (which is an Apache configuration file) we will restrict access for these subdomains

# dont allow acces to the admin controller not under the admin subdomain
RewriteCond %{HTTP_HOST} !^admin.site.com$ [NC]
RewriteCond $1 ^index.php/admin/(.*) [NC]
RewriteRule (.*) http://%{HTTP_HOST}/your-404-page

And the same for the member controller

#dont allow acces to the member controller not under the member subdomain
RewriteCond %{HTTP_HOST} !^member.site.com$ [NC]
RewriteCond $1 ^index.php/member/(.*) [NC]
RewriteRule (.*) http://%{HTTP_HOST}/your-404-page

Remember that once you have the subdomains, if you dont restrict it, users that come to the site under admin.site.com will be able to see all other pages of the site (except members controller) , if you want to restrict their access just to admin controller you will have to add another rewrite rule.

like image 180
Lupin Avatar answered Aug 06 '26 19:08

Lupin