Welcome Guest, Not a member yet? Register   Sign In
subdomains, htaccess, dns wildcards and codeignitor all on the fly
#1

[eluser]bugboy[/eluser]
Hi all

I'm hoping someone can help me with this challenge I have.

I'm attempting to create a service that when users sign up to it creates a subdomain for them on the fly.

for example: user.domain.com

Now I have a wildcard DNS set up on my server so I know it can be done using a .htaccess file to redirect a subdomain to a folder but what i'd like it to do is to redirect to a controller in codeignitor.

This is what I have at the moment .htaccess wise. But for some reasons its not routing right.

Code:
RewriteEngine On
    RewriteOptions inherit
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{HTTP_HOST} !www.domain.com$ [NC]
    RewriteCond %{HTTP_HOST} ^(www.)?([a-z0-9-]+).domain.com [NC]
    RewriteRule (.*) index.php/%2/$1 [L]


How do i access the data from the rerouted url

Any help as i'm not sure i'm on the right track i'm getting a lot of 500 errors if i do this: http://welcome.domain.com/hello
#2

[eluser]Colin Williams[/eluser]
Is the rewrite even necessary? The domain will resolve without it, right? And you don't need to duplicate the subdomain in the path, because, well, it's sitting right there in the URI.

I think you're getting a 500 because your rules look like they'll hit an infinite loop.
#3

[eluser]bugboy[/eluser]
you know i think your right.

All domains will resolve straight away due to the wildcard dns. Oh this is great i think i was making it more difficult then i needed. I'll just use the url.

Cheers for making me see sense.
#4

[eluser]wekadesign[/eluser]
i have setting config.php and fill with this
$config['base_url'] = 'http://'.$_SERVER["HTTP_HOST"].'/';

and when i access all subdomain like http://myallsubdomain.maindomain.com it`s will route to one controller on CI
#5

[eluser]wekadesign[/eluser]
its my .htaccess file

RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ index.php/$1 [L]
#6

[eluser]A83[/eluser]
I'm doing the same thing. The user gets username.domain.com as it's url.

I've set up DNS, .htaccess and get sub domains to go to a different controller than the top domain.

I've got routing that looks like this:

Code:
if($_SERVER['HTTP_HOST'] == "www.domain.com" || $_SERVER['HTTP_HOST'] == "domain.com")
{

// Routes for domain.com

$route['default_controller'] = "domain";

} else {

// Routes for *.domain.com

$route['default_controller'] = "sub";

}

How do I send the user as a "variable" to the sub controller?

Thanks in advance!




Theme © iAndrew 2016 - Forum software by © MyBB