rewrite all subdomains to mainsite.com/controler/subdomain ? |
[eluser]shawndr[/eluser]
I'm no good with htaccess. Would someone please help me accomplish this on a linux server? anysubdomain.example.com needs to rewrite to: example.com/mycontroler/anysubdomain Thank you Shawn
[eluser]Pascal Kriete[/eluser]
I do something similar on my own site using this: Code: RewriteCond %{HTTP_HOST} ^anysubdomain\.example\.com$ [NC] -Pascal
[eluser]shawndr[/eluser]
Thanks for the sample, either I don't get it or I havn't expressed my self correctly. Let me clarify, I need to take the URL and, 1. "cut" the subdomain (whatever it may be) off of the front 2. append a constant controller "mycontroller" 3. append the subdomain on to the end of that. so that: xxxx.mydomain.com becomes mydomain.com/mycontroller/xxxx but I can't write a new condition line for every subdomain there are too many, and they are changeing. Any thoughts on how to do that? Thanks again Shawn
[eluser]Pascal Kriete[/eluser]
Ah ok. So it's more like having a subdirectory for each username. The rewrite should look something like this (not tested): Code: RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com.*$ You'll also need to make sure your dns and web server are set up so that ever requests ends up in the right spot.
[eluser]shawndr[/eluser]
Thank you VERY much! That is exactly what I was hopeing for. Thank you Shawn
[eluser]Kumar Chetan sharma[/eluser]
Let me add more trouble to this. I have 2 controllers, one Site, for plain html requests and one Ajax for Ajax calls. Initially the requirement was to send all requests for to be like following http://www.site.com/sites/username/index.html or http://site.com/sites/username/index.html and http://www.site.com/ajax/ajaxmethods or http://site.com/ajax/ajaxmethods Easy! The situation changed to following http://www.site.com/username/index.html or http://site.com/username/index.html and http://www.site.com/ajax/ajaxmethods or http://site.com/ajax/ajaxmethods I some how managed this with following Code: <IfModule mod_rewrite.c> But life is never simple and now the client has asked me to do this http://www.username.site.com/index.html or http://username.com/index.html and I also have to maintain Ajax calls. I know its easy but I am not able to solve this problem even after 16 hours :-( Any pointer???
[eluser]Phil Sturgeon[/eluser]
http://www.username.site.com/ makes him an idiot. http://username.com/ how would that ever work? AJAX does not work cross-domain (unless you are using 3.5 and have some tricky header work in your code).
[eluser]Kumar Chetan sharma[/eluser]
Hey Phil, Hope you are doing good and have never heard or read following quote. Quote:"It is impossible to make anything fool- proof because fools are so ingenious."I managed to do this and am laughing at my self for my foolishness. Code: Options +FollowSymLinks On ur local windows machine look for hosts file in windows folder/system32/drivers/etc and add some entries for ur subdomain.domain.com Create virtual host for www.domain.com and also add server alias *.domain.com to this virtual host entry. place a print_r($_SERVER) in a php file and see how it works. Regarding Ajax, all my Ajax calls go to a url like /Ajax/mymethods/parameters not to domain.com/Ajax/mymethods/parameters. It seemed tough initially but I found a way to handle all requests that doesn't have subdomain present using php. Looks easy now :-) |
Welcome Guest, Not a member yet? Register Sign In |