Sameed Alam Qureshi
Sameed Alam Qureshi

Reputation: 313

Multi Domains for Codeiginiter

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

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

Upvotes: 3

Views: 119

Answers (2)

El Don
El Don

Reputation: 922

just do this

$config['base_url'] = '';

in config.php for your app and start up

Upvotes: 0

Lupin
Lupin

Reputation: 1244

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.

Upvotes: 1

Related Questions