简体   繁体   中英

Sub-Domain auto pointing

So I am just starting on building a new application with codeigniter. What I am wanting to do is the following.

Have an auto-generated string stored in a database -- got this part covered.

// Auto Generated String    
gc149354

Share the auto-generated string appended to my regular domain name in an email to a client -- got this part covered as well.

// Appended to the domain name
http://gc149354.mycoolurl.com

All this is pretty standard coding with php and codeigniter. But where it gets tricky is actually having that url http://gc149354.mycoolurl.com direct the user somewhere.

I want it to direct the client to a controller in codeigniter called newsite.php which is stored in controllers/new-site/newsite.php And the controller will handle everything from there.

I am imagining I will need something in .htaccess on the root of my directory. Maybe like so:

RewriteEngine On    # Turn on the rewriting engine

RewriteRule     (gc[0-9]+)/     /get-started    [NC]

Except that calls for mycoolurl.com/gc149354 and not gc149354.mycoolurl.com right?

So how can I route all sub-domains that start with gc follwed by 6 numbers 1-9 get routed to the getstarted controller in codeigniter?

Are you referring to something like:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(gc[0-9]+)\.mycoolurl\.com$ [NC]
RewriteRule ^/?$ /controllers/new-site/newsite.php?sub=%1 [L,QSA]

And the "sub" GET parameter will be given the subdomain string. Or, if your controller can look at the subdomain, you can just get rid of the ?sub=%1 part.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM