Dynamic systems to by-pass routing to subdomain's home pages

Using a single web hosting account to host multiple sites

Dynamic systems to by-pass routing to subdomain's home pages

Postby Nols Smit » Mon Nov 27, 2006 5:43 am

Hi,

Background:
I'm using Apache 2.0.54. Under the htdocs folder, I creater some subfolders, one per subdomain (e.g. -fred, -john etc.). Note the names start with a hyphen. The idea is to route users of subdomains to (and lock them into) their allocated folders and subfolders.

However, I have also a few dynamic systems on the same server. Each of these systems consists of a Apache DSO, a FireBird DB and a CSS (no static pages and therefore no subfolders, stating with a hyphen).

Two examples of these systems are:
http://sarnap.nolsmit.com or http://www.nolsmit.com/sarnap
http://geosites.nolsmit.com or http://www.nolsmit.com/geosites
(the second one may also use parameters as reflected in the .htaccess file. Replace nolsmit with infoveld for a live system).

My problem:
In my .htaccess file, if the user access a dynamic system: How do I bypass the code below #-----------Automatically route to subdomain's home page

My complete .htaccess file:
RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteRule ^.htaccess$ - [F]


#-----------Allow/Prevent Directory Browsing
IndexIgnore */*
#Options +Indexes

#-----------Automatically route to subdomain's home page
#(Dynamic systems must bypass this part)
RewriteCond %{REQUEST_URI} !^/-
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)
RewriteCond %{DOCUMENT_ROOT}/-%2 -d
RewriteRule ^(.*)$ -%2/$1 [L]

#-----------Handle search engine friendly parameters
RewriteRule ^(.*)report([0-9]+)-site([0-9]+)$ $1?report_id=$2&site_id=$3
RewriteRule ^(.*)report([0-9]+)-country([0-9]+)$ $1?report_id=$2&country_id=$3
RewriteRule ^(.*)report([0-9]+)-country([0-9]+)-province([0-9]+)$ $1?report_id=$2&country_id=$3&province_id=$4

RewriteCond %{HTTP_HOST} ^geosites\.nolsmit\.com$ [NC]
RewriteRule ^(.*)$ http://www.nolsmit.com/geosites$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^geositesupdate\.nolsmit\.com$ [NC]
RewriteRule ^(.*)$ http://www.nolsmit.com/geositesupdate$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^sageolit\.nolsmit\.com$ [NC]
RewriteRule ^(.*)$ http://www.nolsmit.com/sageolit$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^geoinfo\.nolsmit\.com$ [NC]
RewriteRule ^(.*)$ http://www.nolsmit.com/geoinfo$1 [R=301,L]
Nols Smit
 
Posts: 9
Joined: Mon Nov 27, 2006 3:37 am
Location: South Africa

Postby richardk » Mon Nov 27, 2006 10:14 am

After
Code: Select all
#-----------Automatically route to subdomain's home page

add
Code: Select all
# subdomains to ignore
RewriteCond %{HTTP_HOST} !^(www\.)?(one|two|three|etc.)\.domain\.com$ [NC]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Dynamic systems to by-pass routing to subdomain's home pages

Postby Nols Smit » Tue Nov 28, 2006 3:44 am

Hi,

I tried what you suggested but still no joy.

The scaled-down .htaccess file
RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteRule ^.htaccess$ - [F]

#--------Automatically route to subdomain's home page
# subdomains to ignore
RewriteCond %{HTTP_HOST} !^(www\.)?(geosites|sageolit)\.nolsmit\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/-
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)
RewriteCond %{DOCUMENT_ROOT}/-%2 -d
RewriteRule ^(.*)$ -%2/$1 [L]

RewriteCond %{HTTP_HOST} ^(www\.)?geosites\.nolsmit\.com$ [NC]
RewriteRule ^(.*)$ http://www.nolsmit.com/geosites$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^sageolit\.nolsmit\.com$ [NC]
RewriteRule ^(.*)$ http://www.nolsmit.com/sageolit$1 [R=301,L]

My hosts file:
127.0.0.1 localhost
172.16.13.51 www.nolsmit.com
#-------- subdomains for dynamic systems
172.16.13.51 geosites.nolsmit.com
172.16.13.51 sageolit.nolsmit.com
#-------- subdomains for static systems
172.16.13.51 pat.nolsmit.com
172.16.13.51 piet.nolsmit.com

Observed behaviour:
Subdomains for static systems (e.g. http://piet.nolsmit.com) work OK
Subdomains for dynamic systems (e.g. http://geosites.nolsmit.com) give “HTTP 404 Not
Found”

Routing to subdomain home pages cancelled:
If I comment out the statements:
#RewriteCond %{HTTP_HOST} !^(www\.)?(geosites|geositesupdate|sageolit|geoinfo)\.nolsmit\.com$ [NC]
#RewriteCond %{REQUEST_URI} !^/-
#RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)
#RewriteCond %{DOCUMENT_ROOT}/-%2 -d
#RewriteRule ^(.*)$ -%2/$1 [L]

And xmit the address: geosites.nolsmit.com, it get re-writed to:
http://www.nolsmit.com/geosites and then it works OK

Any suggestions:?
Nols Smit
 
Posts: 9
Joined: Mon Nov 27, 2006 3:37 am
Location: South Africa

Postby richardk » Tue Nov 28, 2006 8:52 am

Try:
Code: Select all
Options +FollowSymlinks
IndexIgnore */*

RewriteEngine On
RewriteRule ^\.htaccess$ - [F]

RewriteCond %{HTTP_HOST} ^(geosites|geoinfo|sageolit|geositesupdate)\.nolsmit\.com$ [NC]
RewriteRule ^(.*)$ http://www.nolsmit.com/%1/$1 [R=301,L]

RewriteCond %{HTTP_HOST} !^(www\.)?nolsmit\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.
RewriteCond %{DOCUMENT_ROOT}/-%2 -d
RewriteRule !^(-.*|(geosites|geoinfo|sageolit|geositesupdate)(/.*)?))$ /-%2%{REQUEST_URI} [QSA,L]

RewriteRule ^(.*)report([0-9]+)-site([0-9]+)$                     /$1?report_id=$2&site_id=$3                   [L]
RewriteRule ^(.*)report([0-9]+)-country([0-9]+)$                  /$1?report_id=$2&country_id=$3                [L]
RewriteRule ^(.*)report([0-9]+)-country([0-9]+)-province([0-9]+)$ /$1?report_id=$2&country_id=$3&province_id=$4 [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Nols Smit » Wed Nov 29, 2006 12:53 am

Hi Richard,

I looked at the following posting and reconsidered my setup:
Thread: sub.domain.com/* -> domain.com/sub/* - rewrite by newbiewiz on Sat Sep 30, 2006 5:33 pm

My ServerRoot is the default: C:/Program Files/Apache Group/Apache2

I then reckoned I must change my folder outlay to this pattern:

ServerRoot\domain1.com … root folder for domain1.com
ServerRoot\domain1.com\_sub1 … root folder for first subdomain of domain1.com
ServerRoot\domain1.com\_sub2 … root folder for second subdomain of domain1.com

ServerRoot\domain2.com … root folder for domain2.com
ServerRoot\domain2.com\_sub1 … root folder for first subdomain of domain2.com
ServerRoot\domain2.com\_sub2 … root folder for second subdomain of domain2.com

Therefore:
sub1.domain1.com/index.html ===> "C:\Program Files\Apache Group\Apache2\htdocs\domain1.com\_sub1\index.html"

sub2.domain2.com/index.html ===> "C:\Program Files\Apache Group\Apache2\htdocs\domain2.com\_sub2\index.html"

But dynamic systems must not be routed to a subfolder.

I would like to base it on the following .htaccess code (as displayed on mentioned posting) and also to keep in mind the root folder of subdomains will start with a underscore:
Options +FollowSymlinks
IndexIgnore */*
RewriteEngine On
RewriteRule ^\.htaccess$ - [F]

RewriteCond %{HTTP_HOST} !^(www\.)?nolsmit.com$ [NC]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^([^.]+)\.nolsmit.com$ [NC]
RewriteRule .* /%1%{REQUEST_URI} [QSA,L]

Therefore pat.nolsmit.com/index.html must recall "C:\Program Files\Apache Group\Apache2\htdocs\nolsmit.com\_pat\index.html"

And then there is still the matter of handling the dynamic systems:

RewriteCond %{HTTP_HOST} ^(geosites|geoinfo|sageolit|geositesupdate)\.nolsmit\.com$ [NC]
RewriteRule ^(.*)$ http://www.nolsmit.com/%1/$1 [R=301,L]

RewriteRule ^(.*)report([0-9]+)-site([0-9]+)$ /$1?report_id=$2&site_id=$3 [L]
RewriteRule ^(.*)report([0-9]+)-country([0-9]+)$ /$1?report_id=$2&country_id=$3 [L]
RewriteRule ^(.*)report([0-9]+)-country([0-9]+)-province([0-9]+)$ /$1?report_id=$2&country_id=$3&province_id=$4 [L]

(now that I've a 10% understanding of .htaccess, Egyptian hieroglyphics are real easy :) )
Nols Smit
 
Posts: 9
Joined: Mon Nov 27, 2006 3:37 am
Location: South Africa

Postby richardk » Wed Nov 29, 2006 7:03 am

If you have access to the server configuration you should probably be using mod_vhost_alias.

Have you got <VirtualHost>s for each domain?

What directory (one example) does a dynamic site go to?

What directory would domain.com go to?
What directory would www.domain.com go to?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Nols Smit » Wed Nov 29, 2006 11:37 am

>Have you got <VirtualHost>s for each domain?
No, not configured. If possible, I prefer to use only .htaccess but I have full control over the server.

>What directory (one example) does a dynamic site go to?

The dynamic sites are created by using Delphi and the IntraWeb controls (http://www.atozedsoftware.com). An Apache dll (for Windows) is compiled out. I also use ReportBuilder (http://www.digital-metaphors.com) reporting tool, compiled into the Apache dll. That system allows only one folder (and it’s sub-folders) under ServerRoot\modules\Files. In my case:
C:\Program Files\Apache Group\Apache2\modules\Files

This “Files” folder is used for temporarily output files (html & pdf), the CSS file, favicon.ico and some propriety files for the user to download. In other words, my dynamic systems do not use htdocs and it's sub-folders.

>What directory would domain.com go to?
Without the default www subdomain, it must go to C:\Program Files\Apache Group\Apache2\htdocs\domain.com

>What directory would www.domain.com go to?
Also to C:\Program Files\Apache Group\Apache2\htdocs\domain.com
Nols Smit
 
Posts: 9
Joined: Mon Nov 27, 2006 3:37 am
Location: South Africa

Postby richardk » Wed Nov 29, 2006 2:34 pm

.htaccess files are inefficient and not designed for control of domains and document roots.

Try:
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?(geosites|geoinfo|sageolit|geositesupdate)\.nolsmit\.com$ [NC]
RewriteRule ^(.*)$ http://www.nolsmit.com/%2/$1 [R=301,L]

RewriteCond %{ENV:REDIRECT_STATUS} !^$
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+\.[^\.]+)$ [NC]
RewriteRule !^(geosites|geoinfo|sageolit|geositesupdate).*$ /%2%{REQUEST_URI} [QSA,L]

RewriteCond %{ENV:REDIRECT_STATUS} !^$
RewriteCond %{HTTP_HOST} ^(www\.)?([^\.]+)\.([^\.]+\.[^\.]+)$ [NC]
RewriteRule !^(geosites|geoinfo|sageolit|geositesupdate).*$ /%3/%2%{REQUEST_URI} [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Nols Smit » Thu Nov 30, 2006 4:02 am

I observed the following:
Access to the dynamic systems is OK.

I observed the following when access the static systems:
pat.nolsmit.com/index.html ==> C:\Program Files\Apache Group\Apache2\htdocs\nolsmit.com\_pat\index.html
(would like that pat.nolsmit.com by default recall his index.html)
But pat.nolsmit.com give: HTTP 404 not found

My host file:
127.0.0.1 localhost
#---------First domain
172.16.13.51 www.nolsmit.com
172.16.13.51 pat.nolsmit.com
172.16.13.51 piet.nolsmit.com

#---------Second domain
172.16.13.51 www.acme.com
172.16.13.51 jan.acme.com
172.16.13.51 jeff.acme.com
172.16.13.51 piet.acme.com

#-------- subdomains for dynamic systems
172.16.13.51 geosites.nolsmit.com
172.16.13.51 sageolit.nolsmit.com

Mydeclation of virtual domain in httpd.conf
NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot "C:\Program Files\Apache Group\Apache2\htdocs\nolsmit.com"
ServerName www.nolsmit.com
</VirtualHost>

<VirtualHost *:80>
DocumentRoot "C:\Program Files\Apache Group\Apache2\htdocs\acme.com"
ServerName www.acme.com
</VirtualHost>


To clarify my folder structure:
Image
Nols Smit
 
Posts: 9
Joined: Mon Nov 27, 2006 3:37 am
Location: South Africa

Postby richardk » Thu Nov 30, 2006 9:37 am

Don't bother with all that, just add the _ that i missed into the mod_rewrite.

Code: Select all
/_%2%{REQUEST_URI}

and
Code: Select all
/_%3/%2%{REQUEST_URI}
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Next

Return to Domain Handling

Who is online

Users browsing this forum: No registered users and 20 guests

cron