Using .htaccess for dynamic subdomains |
[eluser]psdtocode[/eluser]
Hello, I'm curious how I would setup my server to use dynamic subdomains. I have full access to http.conf, and the entire server. I want to acheive the effect of WordPress MU, if you know how that works. The site I'm creating allows people to create blog-like sites under my parent domain, so it would be http://sample.mydomain.com/. The domain would then route to a URL such as: Code: http://mydomain.com/site_manager/index.php/site/view/sample I've gotten it to be http://mydomain.com/site/view/sample (couldn't get rid of the site/view/ part) for basic testing, however I am wanting to reroute the URL's to how they would be on the live site. Examples: Code: http://sample.mydomain.com/ Code: http://mydomain.com/site_manager/index.php/site/view/sample Code: http://sample.mydomain.com/post/123 Code: http://mydomain.com/site_manager/index.php/site/view/sample/post/123 Horrible URL structure in my opinion, but I don't know how else I could structure it. Thanks, Andrew
[eluser]DPrevite[/eluser]
In the past I've put this in my config file: Code: // May not be the best place to put this, but... And then the rest of the code uses the subdomain name in the where clause when it does select statements, etc using: Code: $this->config->item('subdomain');
[eluser]Thorpe Obazee[/eluser]
may be you should also see if the user did use a subdomain? I haven't actually tried your solution but I might try it for my pet project.
[eluser]DPrevite[/eluser]
I had a .htaccess file that forced the www to show up, so if you went to http://example.com it would redirect to http://www.example.com and then the subdomain would be www. If you wanted it to work without you could just add a check to see if there is a subdomain or not and then set the basedir differently.
[eluser]uptime[/eluser]
[quote author="DPrevite" date="1227607306"]I had a .htaccess file that forced the www to show up, so if you went to http://example.com it would redirect to http://www.example.com and then the subdomain would be www. If you wanted it to work without you could just add a check to see if there is a subdomain or not and then set the basedir differently.[/quote] That would do: Code: <IfModule mod_rewrite.c>
[eluser]Phil Sturgeon[/eluser]
Something like the following would do both. If it doesnt start with www. and it has a subdomain, send it to whatever URL you like. Otherwise, make sure it has www. at the start and send it to the main site. Code: <IfModule mod_rewrite.c>
[eluser]Phil Sturgeon[/eluser]
Afterthought, if you have mod_proxy enabled in your apache httpd.conf you can add the P flag to those rules to keep it using the subdomains instead of a 301 redirect. Try this: Code: <IfModule mod_rewrite.c> This will cause unknown and untested issues with the base_url. Can someone try this out and let me know what happens? No internet at home... STILL!
[eluser]uptime[/eluser]
thepyromaniac: Why don't you check it at home? Local Apache + hosts file... :-)
[eluser]Phil Sturgeon[/eluser]
Never got round to setting up mod_redirect on my local setup. Tried once a few months back, then decided iI was busy enough with paid work. REALLY need to have another crack at that one >.< Its normally easy enough, but for some reason I decided to try and slap the baked-in Leopard Apache setup into shape, instead of just installing MAMP. Why oh why... ![]() Anyway, does this work for you?
[eluser]_sty_[/eluser]
Code: <IfModule mod_rewrite.c> Hi guys could anybody assist how to combine these solution specified above with the default CI htaccess for excluding index.php from url Code: RewriteCond $1 !^(index\.php|static|js|images|robots\.txt) I.e. I mean how to collect it in a one file? Thanks beforehand! |
Welcome Guest, Not a member yet? Register Sign In |