Wildcard subdomains and routing |
Howdy,
I'm currently using CodeIgniter 3. I want to create dynamic subdomains like team1.domain.com, team2.domain.com, etc. These domains need to point to the controller Team and a specifically to the show_Team method in the that controller. Routing is as follow PHP Code: $route['team/(:any)'] = "Team/show_Team"; I had severall rules in the .htaccess, but these do a redirect to /team/team1, but I want to work from the subdomain. Like as said team1.domain.com Anyone an idea
You need to use RewriteRule instead of a redirect inside your htaccess file.
Thanks Diederik for your answer
I have the following Code: # If it's not starting with www However its using a RewriteRule
I'm not quite a htaccess guru but the rewrite rule looks ok, atleast your not using a [R] flag for a redirect. Are you shure the redirect is cause by the htaccess file?
I am not sure if its the .htaccess or something else
The complete .htaccess is Code: <IfModule mod_rewrite.c> As you can see the last RewriteRule is changed. For now when I go to https://team1.domain.com, the address bar shows https://domain.com/team/team1. The route PHP Code: $route['team/(:any)'] = "Team/show_Team/$1"; The problem is that the URL changes.
If you want to work with the HTTPS (SSL) protocol in all the calls to the subdomains, you must make the DNS Dynamic and change in the DNS Manager from your Domain Manager this:
add a register type A and in the name put * and in value put the ip from your site or if the site is the same where would be the domain then put @ in php you too get the subdomain and work with this without .htacces modifications, the difference is that in this php version dont change or hidde the subdomain in the address bar call $array = explode('.',$_SERVER['SERVER_NAME']); $parameter1=$array[0]; if($parameter1 != 'www') { //do this tasks for this parameter in the subdomain // go to this page or controll } //run the controller from index.php (www.domain.com or domain.com) |
Welcome Guest, Not a member yet? Register Sign In |