3

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

Sameed Alam Qureshi
  • 293
  • 1
  • 3
  • 15
  • I think you should use wildcard sub domain feature. – Sagar Khatri Apr 16 '15 at 11:39
  • Check this [answer](http://stackoverflow.com/questions/183928/how-to-let-php-to-create-subdomain-automatically-for-each-user#answer-183971). Most of questions are already answered, query for some on [google](https://www.google.ba/search?q=dinamically+creating+subdomain&oq=dinamically+creating+subdomain&aqs=chrome..69i57.7235j0j4&sourceid=chrome&es_sm=93&ie=UTF-8#q=dynamically+creating+subdomain&spell=1) or even here in search field. :) – Tpojka Apr 16 '15 at 14:21

2 Answers2

1

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 & admin@site.com

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.

Lupin
  • 1,225
  • 11
  • 17
  • thank for this is only reply for restricted to domain please tell me how to create sub domain for codeiginter – Sameed Alam Qureshi Apr 18 '15 at 13:25
  • You will have first to create the subdomain in your server so your web server will know where to forward requests to those subdomains, then in CodIgniter you will need to set the base_url variable. – Lupin Apr 19 '15 at 06:10
0

just do this

$config['base_url'] = '';

in config.php for your app and start up

El Don
  • 902
  • 7
  • 14