Page 1 of 1
Make subdomains work...
Posted: Mon Nov 03, 2008 6:25 pm
by yabune
Hi,
I have a site with two subdomains. Both subdomains point to the root (where cmsms is installed).
I have something like this:
www.domain.net
sub1.domain.net
sub2.domain.net
All pointing to the same site.
I have 2 questions:
1) what do I have to put in .htaccess so that when I enter with one of the subdomains, it shows in the url box the url of the subdomain? (it shows always
www.domain.net)
2) how do I know in which subdomain I am? With: $smarty.server.SERVER_NAME ?
Thank you!
Re: Make subdomains work...
Posted: Mon Nov 03, 2008 10:17 pm
by nhaack
How did you create your sub-domains? Often, your web-space provider offers a comfortable way to assign sub-domains to other folders in your webspace.
Best
Nils
Re: Make subdomains work...
Posted: Tue Nov 04, 2008 10:46 am
by yabune
Thank you nhaack, but I want the subdomains to point to the same place as the root.
I would like to have the same site, but depending of the subdomain, I would show some defined content for that subdomain.
I've seen a similar question in this thread:
http://forum.cmsmadesimple.org/index.php/topic,22890.0.html
But in here they have parked domains instead of subdomains.
Re: Make subdomains work...
Posted: Tue Nov 04, 2008 10:53 am
by nhaack
I see...
So what is your desire? What content do you want to show for the different sub-domains? For example, I have another site and sub-domain and whenever the site is called via this sub-domain, a different template is used. Would that be what you are looking for?
Or do you want to map the subdomain to specific content branches? Or add some specific content if the site is requested from a subdomain?
Best
Nils
Re: Make subdomains work...
Posted: Tue Nov 04, 2008 1:05 pm
by yabune
This site is for a music school, but they have two "sub-schools". I would like to have the same template as some content is equal like the instruments they teach, and some articles like the history of the school, the prices... But I would like that the text show in the main page, and the news articles are different for each school.
Maybe the best solution would be to map the root domain to a template that only asks which school I would like to enter. And then each subdomain would share the same template with some common content and some independent content that is specific for that subdomain.
Do you have any tips on this?
Thanks a lot!
Re: Make subdomains work...
Posted: Tue Nov 04, 2008 1:39 pm
by nhaack
I think I have an idea, depending on what sub domain ahs been selected, you could attach a parameter to the single pages using rewrite rules.
Then, depending on the existance of this parameter, you show an additional content block that shows the sub schools specific content. The following rewrite rules might be helpfull for this:
Code: Select all
# Rewrite to home.htm if url does not contain a specific page
# e.g. http://www.domain.tld
# ==================================================
# Checks if requested URI is "empty" and rewrites
# it from http://www.domain.tld to
# http://www.domain.tdl/home.htm
# ==================================================
RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteRule .* /home.htm
# OTHER TEMPLATE IF PAGE IS LOCATED UNDER SUBDOMAIN
# ==================================================
# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
# additionally appends the parameter "template" with the value="mobile"
# to the query string
# ==================================================
RewriteCond %{HTTP_HOST} ^subdomain1\.domain\.tld$ [NC]
RewriteRule ^(.+).htm$ index.php?page=$1&template=subdomain1 [QSA,L]
Within your actual page template, you check for the parameter value like this:
Code: Select all
{if $smarty.get.template == 'subdomain1'}
{content block="subdomain1_specific_content"}
{/if}
For the editorial workflow, you would now maintain the pages for each school within one page. However, this way, all sites would have an equal page hierarchy...
So you would have a structure in which you have generic content on a page for all schools and specific content for each school. Repeat the if loops for any additional subdomains.
I use this to generate a low-fi version of a site where I need the identical structure. Don't know if that's the right thingy for you....
Probably this can give you a little kick-start
Best
Nils
Re: Make subdomains work...
Posted: Thu Nov 06, 2008 6:28 pm
by yabune
Thanks! It looks like what I want.
I did what you said (the second part) and if I go to subdomain1.domain.tld it works ok, and it goes to the homepage and it shows in url box subdomain1.domain.tld. But if I entered subdomain1.domain.tld/somepage it goes to that page but the url box says domain.tld/somepage (without the subdomain).
Is it possible to show subdomain1.domain.tld/somepage?
This is my current .htaccess:
Code: Select all
# BEGIN Optional settings
# Turns off directory browsing
# not absolutely essential, but keeps people from snooping around without
# needing empty index.html files everywhere
Options -Indexes
# Deny access to config.php
# This can be useful if php ever breaks or dies
# Use with caution, this may break other functions of CMSms that use a config.php
# file. This may also break other programs you have running under your CMSms
# install that use config.php. You may need to add another .htaccess file to those
# directories to specifically allow config.php.
<Files "config.php">
order allow,deny
deny from all
</Files>
# Sets your 403 error document
# not absolutely essential to have,
# or you may already have error pages defined elsewhere
ErrorDocument 403 /forbidden403.shtml
# No sense advertising what we are running
ServerSignature Off
# END Optional Settings
# BEGIN CMSMS and Rewrite Rules
# Make sure you have Options FollowSymLinks
# and Allow on
RewriteEngine On
# Might be needed in a subdirectory
#RewriteBase /
# URL Filtering helps stop some hack attempts
#IF the URI contains a "http:"
RewriteCond %{QUERY_STRING} http\: [OR]
#OR if the URI contains a "["
RewriteCond %{QUERY_STRING} \[ [OR]
#OR if the URI contains a "]"
RewriteCond %{QUERY_STRING} \] [OR]
#OR if the URI contains a "<__script__>"
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
#OR script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
#OR any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
RewriteRule ^.*$ - [F,L]
# END Filtering
RewriteCond %{HTTP_HOST} ^subdomain1\.domain\.tld$ [NC]
RewriteRule ^(.+).htm$ index.php?page=$1&template=subdomain1 [QSA,L]
# CMSMS Rewriting
# Set assume mod_rewrite to true in config.php and clear CMSMS cache
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]
# END CMSMS
# END Rewrite rules
Re: Make subdomains work...
Posted: Thu Nov 06, 2008 10:31 pm
by nhaack
Strange... but I must admit I am not that much of a url rewriting crack. I pretty much have the same settings and it works fine for me.
So I do not see the big difference, except for allowing to follow symbolic links and that the last conditions are not case sensitive. There are a few more conditions in the URL filtering but I do not see a reason why your's shouldn't work.
I am not quite sure, but probably this has something to do with your hosting. What happens when you upload a static file to your webspace and when you try to get it through the subdomain?
Oh, I wait I think I see it. When you rewrite from the subdomain... your rewrite condition is:
Code: Select all
RewriteCond %{HTTP_HOST} ^subdomain1\.domain\.tld$ [NC]
RewriteRule ^(.+).htm$ index.php?page=$1&template=subdomain1 [QSA,L]
But since you are not uring the htm extension, change it to:
Code: Select all
RewriteCond %{HTTP_HOST} ^subdomain1\.domain\.tld$ [NC]
RewriteRule ^(.+)$ index.php?page=$1&template=subdomain1 [QSA,L]
Try it out and let me know. I think this could be the trick.
Best
Nils
Re: Make subdomains work...
Posted: Fri Nov 07, 2008 12:34 pm
by yabune
It stills doesn't work very well.
I was testing in chrome, but now I'm testing in firefox and it goes back always to the url without subdomain.
Could it be the follow symbolic links? Or should i configure something in config.php?
If I try to get a static file through the subdomain I can get the file, but the url changes to an url without subdomain.
Thanks!
Re: Make subdomains work...
Posted: Fri Nov 07, 2008 9:49 pm
by nhaack
mhh... I think it has something to do with your servers settings. I do not think it has anything something to do with the config.php... the follow symlink option also shouldnÄt be the problem...
here is my full .htaccess... probably it helps you somehow...
Code: Select all
AddType x-mapp-php5 .php
AddHandler x-mapp-php5 .php
Options +FollowSymLinks
RewriteEngine on
#option to remove directory listings in all folder (avoid publishing unwanted contents)
Options -Indexes
# Deny access to config.php
# This can be useful if php ever breaks or dies
# Use with caution, this may break other functions of CMSms that use a config.php
# file. This may also break other programs you have running under your CMSms
# install that use config.php. You may need to add another .htaccess file to those
# directories to specifically allow config.php.
<Files "config.php">
order allow,deny
deny from all
</Files>
# URL Filtering helps stop some hack attempts
#IF the URI contains a "http:"
RewriteCond %{QUERY_STRING} http\: [OR]
#OR if the URI contains a "["
RewriteCond %{QUERY_STRING} \[ [OR]
#OR if the URI contains a "]"
RewriteCond %{QUERY_STRING} \] [OR]
#OR if the URI contains a "<__script__>"
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
#OR if the script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
#OR if any script is trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2}) [OR]
#OR if the URI contains UNION
RewriteCond %{QUERY_STRING} UNION [OR]
#OR if the URI contains a double slash
RewriteCond %{QUERY_STRING} // [OR]
#OR if the URI contains a *
RewriteCond %{QUERY_STRING} \*
#then deny the request (403)
RewriteRule ^.*$ - [F,L]
# End URL Filtering
# No sense advertising what we are run
ServerSignature Off
RewriteBase /
# 301 Redirect all requests that don't contain a dot or trailing slash to
# include a trailing slash
# RewriteCond %{REQUEST_URI} !/$
# RewriteCond %{REQUEST_URI} !\.
# RewriteRule ^(.*) %{REQUEST_URI}/ [R=301,L]
# Rewrite to home.htm if url does not contain a specific page
# e.g. http://www.domain.tld
# ==================================================
# Checks if requested URI is "empty" and rewrites
# it from http://www.domain.tld to
# http://www.domain.tdl/home.htm
# ==================================================
RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteRule .* /home.htm
# OTHER TEMPLATE IF PAGE IS LOCATED UNDER SUBDOMAIN
# ==================================================
RewriteCond %{HTTP_HOST} ^lofi\.domain\.com$ [NC]
RewriteRule ^(.+).htm$ index.php?page=$1&template=lofi[QSA,L]
# FOR REGULAR SITE
# ==================================================
# Rewrites urls in the form of /parent/child/
# but only rewrites if the requested URL is not a file or directory
# ==================================================
RewriteCond %{REQUEST_FILENAME} !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d [NC]
RewriteRule ^(.+).htm$ index.php?page=$1 [QSA]
If that doesn't help and none of the other members has any idea, I would contact your hosting service. When you call your uploaded file via the subdomain, the subdomain should stay, so it seems as if you have some sort of redirect set that shouldn't be...
Best
Nils
Re: Make subdomains work...
Posted: Sat Nov 15, 2008 9:59 am
by JeremyBASS