• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use the 3rd level domain?

#1
[eluser]@ndrea[/eluser]
Hi guys,
in these days I'm thinking about deleting my own framework and convert all the whole project to CI.
For a few days I've been reading in forums and wiki to understand CI, I can do all I need and now I have a question of absolute importance.

All 3rd level domains on my server point to root, all these paths link to the same page:
mysite.com/page.html
abc.mysite.com/page.html
xyz.mysite.com/page.html


This is because 'abc' and 'xyz' are used as account name, in the specific case 'mysite.com' links to an information page and to the real site working behind a "specific account request".
First, I wonder what the right configuration for '$config['base_url']' is.
Second, I wonder what is the best practice to create the account mapping: in the actual implementation I use mod_rewrite to take the 3rd level domain and append at querystring like "&account=my3rdLvl".
Third, how can link to the help page when I don't have the account set?

Thanks.
A.

#2
[eluser]TheFuzzy0ne[/eluser]
If you want to redirect to another URL, I'd imagine that only DNS or .htaccess will be the only things that work. I'm trying to imagine how your users would access their sites, and I can't see how they could via CodeIgniter. You'd want to do a hard direct before any files are read from the Web root, would you not?

#3
[eluser]jcavard[/eluser]
Your best bet would be to download a copy of CI and play around. Try out a few scenario on a dummy app, it's easy and so much funTongue

My guest would be (if it is ever possible)
Code:
$config[‘base_url’] = http://mysite.com/
with some mod rewrite magic, but again, that one is tricky!

good luck bro

#4
[eluser]darkbrian[/eluser]
I'm actually building a site right now that has a similar feature, and am doing it with an .htaccess file. If you go to www.MYDOMAIN.com it goes to the default controller as expected. if you goto word.MYDOMAIN.com it sends it to www.MYDOMAIN.com/index.php/word/sites. Thus, for every subdomain, I just need to then have a controller for every 'subdomain' and it works great. Additionally, anything I put after the regular domain is passed to the third URI slot (ie. word.MYDOMAIN.com/test = www.mydomain.com/index.php/word/sites/test) You could also pass it in one of the more traditional variable slots - say www.MYDOMAIN.com/index.php/web/sites/word, and do the same thing with just one controller.

Here's my code:
Code:
RewriteEngine On

# Subdomains.

# Select only those that aren't www.
RewriteCond %{HTTP_HOST} !^www\.MYDOMAIN\.com

# Get the subdomain and first directory.
RewriteCond %{HTTP_HOST}---%{REQUEST_URI} ([^.]+)\.MYDOMAIN\.com---/([^/]+)? [NC]

# Rewrite to the correct place.
RewriteRule ^(.*)$ http://www.MYDOMAIN.com/index.php/%1/site/$1 [P,QSA]

There may be other ways, but I've found that this works grea for me so far.

#5
[eluser]TheFuzzy0ne[/eluser]
Are there any sites you know of that use a similar system, that I can see working? I'm intrigued but I still can't get my head around how it would work.

#6
[eluser]@ndrea[/eluser]
[quote author="TheFuzzy0ne" date="1234489395"]If you want to redirect to another URL, I'd imagine that only DNS or .htaccess will be the only things that work. I'm trying to imagine how your users would access their sites, and I can't see how they could via CodeIgniter. You'd want to do a hard direct before any files are read from the Web root, would you not?[/quote]

I'm sorry, I probably did't explain my problem well, I'll try with an example.
mysite.com is a portal with maps, images and videos from different locations and 'abc', 'xyz' are city names such as 'Rome' and 'Milan'.

When an user goes to mysite.com, he sees a page with information: "Hi, I'm a very cool portal!".
If the user wants to see the content he must go directly to the city home page with the correct url (eg. milan.mysite.com).
The word 'milan' is used to specify the right city in the DB query. Good examples for controller, action and id are: 'images', 'maps' or 'videos' for controller; 'gallery', 'upload' or 'comments' for action and 'id' is the database id for a specific video or image.

At the moment I use htaccess with that rule to take the 3rd level domain:

Code:
RewriteCond %{SERVER_NAME} ^([^.]*)\.(.*\..*)$
RewriteCond %{SERVER_NAME} ^(w+)\..*$
RewriteRule ^(.*)$ %1/index.php [QSA,NC]
RewriteRule ^(.*)$ index.php?city=$1 [L,QSA]

I don't remember the real reason for the first rewrite, but it worked after I wrote it twice.

Bye.
A.

#7
[eluser]@ndrea[/eluser]
Where is the problem???

Code:
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteBase /

RewriteCond %{SERVER_NAME} !^mysite\.it$ [NC]
RewriteCond %{SERVER_NAME} !www\.mysite\.it$ [NC]
RewriteCond %{SERVER_NAME} ^(www.)?([a-z0-9-]+)\.mysite\.it [NC]
RewriteRule (.*) $1?myvar=%2 [L]

With http://abc.mysite.it work, but with http://abc.mysite.it/index.php my server out Error 500 Internal Server Error...

Thanks.
A.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.