0
votes

I found some interesting thoughts here on stackoverflow, but none is stated clearly enough for me, so I have to ask myself if it even could be done :)

Situation:

I have linux with apache http server installed and a bunch of sites in folders in www directory with different contents.

Let's say:

www/Site1 (Phpbb)
www/Site2 (Wordpress)
www/Site3 (Own web pages)

I own one domain intended for use on Site3 (let's call it site3.com, www.site3.com). I have created two more domains at no-ip.org (let's call them site1.sytes.net and site2.sytes.net). All three created domains are pointed to port 80 of linux (apache) servers ip address.

So we have these domains ready:

www.site3.com
site1.sytes.net
site2.sytes.net

Now the question:

How to create redirects to particular directories for users who want content from those domains. I want user who want to get "site1.sytes.net" (and wrote that to browser) to be pointed to Site1 directory and rewrite browser address to omit that directory and put just "http://site1.sytes.net".

For example:

User want: site1.sytes.net [/index.html]
Server goes to: www/Site1 [/index.html]
User see in browser: http://site1.sytes.net [/index.html]

And so on:

site2.sytes.net [/index.html] => www/Site2 [/index.html]
www.site3.com [/index.html] => www/Site3 [/index.html]

If I am not mistaken HTTP_HOST will return just domain, so it is useless for trying to find out what user wrote to browser for site1.sytes.net and site2.sytes.net (because it will return just sytes.net).

1
faqforge.com/linux/… If that doesn't work it's probably because no-ip.org is converting the request into the most recently-cached IP address for your server. - Alex W

1 Answers

0
votes

The %{HTTP_HOST} is indeed what you want, and yes, it only matches the domain. But you use it in a condition and you use either %{REQUEST_URI} or the rule itself to match against the URI. Try putting this in your htaccess file in your document root (which I assume is the same for all your sites, otherwise, there's no point in doing any of this):

RewriteEngine On
RewriteCond %{HTTP_HOST} site1.sytes.net [NC]
RewriteCond %{REQUEST_URI} !^/Site1
RewriteRule ^(.*)$ /Site1/$1 [L]

RewriteCond %{HTTP_HOST} site2.sytes.net [NC]
RewriteCond %{REQUEST_URI} !^/Site2
RewriteRule ^(.*)$ /Site2/$1 [L]

RewriteCond %{HTTP_HOST} www.site3.com [NC]
RewriteCond %{REQUEST_URI} !^/Site3
RewriteRule ^(.*)$ /Site3/$1 [L]