htaccess Elite

.htaccess tutorial


All times are UTC [ DST ]





Post new topic Reply to topic  [ 14 posts ] 
Author Message
 Post subject: Multisite configuration
PostPosted: 08 Nov 2006 00:27 
Offline

Joined: 08 Nov 2006 00:24
Posts: 7
I have a main website of example.com, and I want to add a second (and more) domain named example2.com, with a home directory of example.com/example2/

example2.com is a "parked" domain name, ie it is initially directed to the public root directory of example.com, the main account.

I am told I need htaccess coding that will

1. set the public root directory of example2.com to example.com/example2/

2. retain the visible url of example2.com *after* internal redirection to example2's public root directory

So the user types example2.com, is taken to the public root directory of example2.com (through htaccess programming), sees example2.com in the URL field of the browser, but in fact has been taken "underneath" to example.com/example2.

Can anyone show me how this is done, or point me to some documentation?

Thanks!

- Henrik


Top
 Profile  
 
 Post subject:
PostPosted: 08 Nov 2006 00:58 
Offline
User avatar

Joined: 25 Sep 2006 04:48
Posts: 242
Code:
RewriteCond   %{HTTP_HOST}                 ^example2\.com$
RewriteRule   ^example2\.com(.*) /example2/


Top
 Profile  
 
 Post subject:
PostPosted: 08 Nov 2006 04:13 
Offline

Joined: 08 Nov 2006 00:24
Posts: 7
produke wrote:
Code:
RewriteCond   %{HTTP_HOST}                 ^example2\.com$
RewriteRule   ^example2\.com(.*) /example2/


Thanks produke.

I added the following to my example.com root public directory:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^example2\.com$
RewriteRule ^example2\.com(.*) /example2/

But it didn't do anything.

I removed the space in the last line just to see if it was "listening", and it is (generated an error), but formatted as you have it, there was no effect, it was ignored, so example.com and example2.com are still equivalent.

What am I missing? Could you give me a quick narrative of the logic?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: 08 Nov 2006 23:00 
Offline
User avatar

Joined: 25 Sep 2006 04:48
Posts: 242
Ok try this one:

Code:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond   %{HTTP_HOST} ^www\.example2\.com$ [OR]
RewriteCond   %{HTTP_HOST} ^example2\.com$
RewriteRule  ^(.+)  /example2/$1  [L]




This says that if the visitor requests http://www.example2.com or http://example2.com (those will be the values of the HTTP_HOST variable) then Rewrite all requests to the server internally to the /example2/ folder.

And if the request is example2.com/this/index.html the ($1 above) will carry that over internally to mean /example2/this/index.html

Let me know if it works!


Top
 Profile  
 
 Post subject:
PostPosted: 10 Nov 2006 05:04 
Offline

Joined: 08 Nov 2006 00:24
Posts: 7
There appears to be something really basic that I'm missing.

If I write

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^bechmann\.ca$ [OR]
RewriteCond %{HTTP_HOST} ^www\.bechmann\.ca$
RewriteRule ^(.*) $1

and then enter bechmann.ca to the browser URL field, I get an error 500

if I enter bechmann.ca/test.php I'm OK

if I enter bechmann.ca/osscommons/home/test.php I'm OK

If I change the RewriteRule to

RewriteRule ^(.*) /osscommons/home/$1

And then enter bechmann.ca/test.php I get an error 500

If I change the RewriteRule to

RewriteRule ^(.*) /var/vhosts2/henrik/public_html/osscommons/home/test.php

and enter bechmann.ca

It works, but if I do

RewriteRule ^(.*) /var/vhosts2/henrik/public_html/osscommons/home/osscommons.html

and enter bechmann.ca

I get the contents of the html page, but the styling (ie the relative directory addressing) is lost.

If I do

RewriteRule ^(.*) /var/vhosts2/henrik/public_html/osscommons/home/$1

and enter bechmann.ca/test.php or bechmann.ca/osscommons.html I get an error 500

I have no freakin' idea what's going on, and I've been tinkering for hours.

What am I missing here? Can you give me a concept? or a configuration clue??

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: 19 Nov 2006 01:54 
Offline
User avatar

Joined: 25 Sep 2006 04:48
Posts: 242
So lets say you have 4 domain names you want on this server.

example.com
example1.com
example2.com
example3.com



Ok I'm assuming that your Master DOCUMENT_ROOT folder is /var/vhosts2/henrik/public_html/
if it is actually
/var/vhosts2/henrik/public_html/example.com/ then that is your Master DOCUMENT_ROOT folder.

In that folder create a folder for each of the domain names u want to host. Each domain needs its own folder to act as a virtual document root.

Code:
example.com       -> /var/vhosts2/henrik/public_html/example/
example1.com     -> /var/vhosts2/henrik/public_html/example1/
example2.com     -> /var/vhosts2/henrik/public_html/example2/
example3.com     -> /var/vhosts2/henrik/public_html/example3/



Now put your .htaccess file in the Master DOCUMENT_ROOT folder referenced above. /var/vhosts2/henrik/public_html/.htaccess

the htaccess file:
Code:
Options +ExecCGI
RewriteEngine On
RewriteBase /

# if the internal redirect in the 2nd rewriterule works this
# rule stops the rewriteengine from looping continually
RewriteCond %{ENV:REDIRECT_STATUS} ^200.*
RewriteRule ^ - [L]

# the http_host is www.example.com or example.com or
# example2.com etc.  This grabs whatever is before the .com
# and after the www.  so it will be example or example2 or example3
# and puts that in the variable %2.  so this redirects internally requests
# example.com-> from / -> /example/
# example2.com-> from / -> /example2/
# example3.com-> from / -> /example3/
# example4.com-> from / -> /example4/
#
# so a request for example3.com/test/index.html is served from
# /var/vhosts2/henrik/public_html/example3/test/index.html
RewriteCond %{HTTP_HOST} ^([a-z]+\.)?(.+)\.[a-z]+$ [NC]
RewriteRule ^(.*)$ %2/$1[L]


Top
 Profile  
 
 Post subject:
PostPosted: 19 Nov 2006 02:35 
Offline

Joined: 08 Nov 2006 00:24
Posts: 7
Thanks produke!

Checking of redirect to stop the recursion is very interesting, and I will add it to my kitbag.

Here's what I developed in the meantime, and it seems to work for now, though some may say it has a bit too much overhead:

RewriteEngine on
RewriteBase /
#filter out subdomains: subdomain.domain.com etc. don't need processing
RewriteCond %{HTTP_HOST} !^(www\.)?([^.]*)(\.ca|\.com|\.org)$
RewriteRule ^ - [L]
#extract core domain name
RewriteCond %{HTTP_HOST} ^(www\.)?([^.]*)(\.ca|\.com|\.org)$
RewriteRule ^ - [E=coreName:%2]
#filter out add-on accounts, they don't need processing
RewriteCond %{ENV:coreName} ^dufferinpark$|^parkcommons$|^communitycommons$|^businesscommons$|^wikiwebsites$
RewriteRule ^ - [L]
#if no file is requested, add index.php if available or index.html as default
RewriteCond %{DOCUMENT_ROOT}/%{ENV:coreName}/index.php -f
RewriteRule ^$ http://%{HTTP_HOST}/index.php [R,L]
RewriteRule ^$ http://%{HTTP_HOST}/index.html [R,L]
#add trailing slash if a directory is called without one, avoid canonical domain
RewriteCond $1 ![.]
RewriteCond %{DOCUMENT_ROOT}/%{ENV:coreName}/$1 -d
RewriteRule ^(.+[^/])$ http://%{HTTP_HOST}/$1/ [R,L]
#avoid recursion by checking for sentinel file
RewriteCond %{DOCUMENT_ROOT}/$1/%{ENV:coreName}.identifier.DoNotTouch -f
RewriteRule ^([^/]*) - [S=1]
#silently insert base directory for all other calls to simulate independence
RewriteRule ^(.*)$ %{ENV:coreName}/$1

As you can see the hack required is presence of a sentinel file in each domain directory.

Your comments on this are very welcomed.

So far it seems to work for all cases, but I will definitely investigate your far more concise alternative.

Thanks again.

- Henrik


Top
 Profile  
 
 Post subject:
PostPosted: 15 Dec 2006 21:39 
Offline

Joined: 15 Dec 2006 20:51
Posts: 3
Hi, great place ... lucky I found you guys on google ...

But still I`m sad that it does not work in my situation,

I also have a bussines site http://www.auto-rijbewijs.nl and besides other domains registred by me atached to the main hosting site. Through my provider I can forward the right map to it, but it still shows ipo http://www.barta.nl http://www.auto-rijbewijs.nl/barta/index.html or php, I am desperate cause I`ve tryed many solutions that I could get on the net.

If you need more info about the apache php info file, here it is:

http://www.auto-rijbewijs.nl/phpinfo.php

someone help me plzzz !


Top
 Profile  
 
 Post subject:
PostPosted: 15 Dec 2006 22:13 
Offline

Joined: 08 Nov 2006 00:24
Posts: 7
Hi Cris,

Could you post your RewriteCode?

(I'm not an expert, although according to the scars on my back I've learned a bit <g>).

Is http://www.barta.nl a parked domain name, a subaccount, or a subdomain?

- Henrik


Top
 Profile  
 
 Post subject:
PostPosted: 15 Dec 2006 22:36 
Offline

Joined: 15 Dec 2006 20:51
Posts: 3
Options +ExecCGI
RewriteEngine On
RewriteBase /

# if the internal redirect in the 2nd rewriterule works this
# rule stops the rewriteengine from looping continually
RewriteCond %{ENV:REDIRECT_STATUS} ^200.*
RewriteRule ^ - [L]

# the http_host is http://www.ionescu.nl or ionescu.nl or
# ionescu.nl etc. This grabs whatever is before the .nl
# and after the www. so it will be ionescu or barta
# and puts that in the variable %2. so this redirects internally requests
# ionescu.nl-> from / -> /ionescu/
# barta.nl-> from / -> /barta/
#
# so a request for barta.nl/index.html is served from
# /www/barta/index.html
RewriteCond %{HTTP_HOST} ^([a-z]+\.)?(.+)\.[a-z]+$ [NC]
RewriteRule ^(.*)$ %2/$1[L]

this is how I paste it and remade it ...

about your question if it`s parked ? I don`t know ... I just reserved this names with my provider and those ware attached to the main contract http://www.auto-rijbewijs.nl , like you can see even that don`t work anymore ... so it`s pretty fuc**ed up ! so I realy need some help ..


Top
 Profile  
 
 Post subject:
PostPosted: 16 Dec 2006 03:12 
Offline

Joined: 08 Nov 2006 00:24
Posts: 7
A couple of ideas.

1. The apache engine looks for a *file* in the end, so it will try to append /index.html or /index.php (or whatever the setting is for your environment) to a plain url and then rerun the process. That's why I explicitly set the file name if no file is included in the url request, before resetting the directory (see previous notes). ^$, ie no string for the file means that no file request is included in the url, and should trigger a file insertion in your url to preempt url reformatting. After setting a file, I explicitly rerun the process with [R,L] to preserve the original url form. Only after detecting a file do I rewrite the underlying file location.

2. Check your regular expression in a regular expression calculator. Your regular expression returns "barta." (with the period). I fooled around with http://www.quanetic.com/regex.php for instance, and found that this worked better:

/^(www.)?([^.]*).nl$/ (the leading and trailing "/" is for the expression calculator only, delimiting the regular expression)

or perhaps /^(www.)?([^.]*)/ (without the end of line marker)

With this regex, http://www.barta.nl yields "www." in field one, and "barta" in field 2. Thus you could do

RewriteCond %{HTTP_HOST} ^(www.)?([^.]*)
RewriteRule ^(.*)$ %2/$1[L]

...if your barta.nl public directory is in barta/

3. Be patient. It took me two *weeks* to get the results that I wanted to cover all the cases.

Good luck, and I hope this helps.

- Henrik


Top
 Profile  
 
 Post subject: Host Multiple Domains
PostPosted: 20 Feb 2007 04:36 
Offline

Joined: 20 Feb 2007 04:18
Posts: 4
Location: Louisiana
Can you recommend a web hoster? One that allows you to host several domains?

It seems this htaccess is difficult for a beginner. I have no idea how to edit the file.

I was using Bluehost and when you addon a domain it creates what you need. If you add a subdomain it creates a subfolder.

You never have to use / edit / the htaccess files.

Which web hoster are you using now?



Read To Learn ~ Write To Think


Top
 Profile  
 
 Post subject:
PostPosted: 20 Feb 2007 06:36 
Offline

Joined: 08 Nov 2006 00:24
Posts: 7
I'm using webserve.ca but I can't recommend them because I find their technical support unsatisfactory.

I'm prototyping a webhosting environment with them. I thought I would upgrade to a virtual private server with them, but will probably switch to a different service provider when the time comes.

Their technical environment is pretty complete and reasonably flexible however.

- Henrik


Top
 Profile  
 
 Post subject: Re: Host Multiple Domains
PostPosted: 21 Feb 2007 21:36 
Offline
User avatar

Joined: 25 Sep 2006 04:48
Posts: 242
lsuedu wrote:
Can you recommend a web hoster? One that allows you to host several domains?

Which web hoster are you using now?


Cant you see all the banners on this site?!? lol


I have tried dozens of web hosting companies over the years and the best host BY FAR is dreamhost.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 12 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Powered by phpBB