On Wed, Sep 14, 2005 at 09:20:09PM +0200, Marco wrote: > Simo Kauppi ha scritto: > > >On Mon, Sep 12, 2005 at 10:06:06PM +0200, Marco wrote: > > > > > >>I have test with your settings but I have still problems. This is the > >>configuration of 000-domain1.com > >> > >> > >>This is the configuration for 001-domain2.com > >> > >><VirtualHost 1.2.3.4:80> > >> > >>ServerName www.domain2.com > >> > >>DocumentRoot /var/www/domain2/ > >> > >>RewriteCond %{HTTP_HOST} ^.*domain2\.com [NC] > >>RewriteCond %{HTTP_HOST} !^www\.domain2\.com [NC] > >>RewriteCond %{HTTP_HOST} !^$ > >>RewriteRule ^/(.*) http://www.domain2.com/$1 [L,R] > >></VirtualHost> > >> > >>These are the results: > >> > >>http://domain1.com --> http://www.domain1.com OK (and I see domain1 site) > >>http://domain2.com --> http://domain2.com NO!!!! (and I see domain1 > >>site)!!! > >> > >>I would want http://domain2.com --> http://www.domain2.com (and I see > >>domain2 site) > >> > >>Where is the mistake?? > >>Thanks > >> > >>Marco > >> > >> > > > >Hi Marco, > > > >Just like Angelo suggested, the configuration needs the ServerAlias > >directives. If the requested domain does not match any ServerName, the > >first one is served. And then the RewriteCond directive I suggested > >earlier should not be needed. > > > > > > > >>NameVirtualHost 1.2.3.4:80 > >><VirtualHost 1.2.3.4:80> > >>ServerName www.domain1.com > > ServerAlias domain1.com *.domain1.com > >>DocumentRoot /var/www/domain1/ > >>RewriteCond %{HTTP_HOST} ^.*domain1\.com [NC] > >>RewriteCond %{HTTP_HOST} !^www\.domain1\.com [NC] > >>RewriteCond %{HTTP_HOST} !^$ > >>RewriteRule ^/(.*) http://www.domain1.com/$1 [L,R] > >></VirtualHost> > > > >And for the second host ServerAlias domain2.com *.domain2.com > > > >Of course you can change the *. to www if you want those servers only > >respond to domainx.com and www.domainx.com. > > > >Simo > > > Hi, > I have removed the Rewrite rule on my Virtual Host configuration file, I > have added the > rule ServerAlias domain1.com *.domain1.com, and I have restart apache2. > > Test: http://www.domain1.com --> OK > http://domain1.com --> PAGE NOT FOUND ??? > > I have also an other question, using the server alias option when a > client visit http://domain1.com > its URL comes rewritten in http://www.domain1.com???? > > Help!!! > Thanks > > Marco
Hey Marco, I thought I knew what you was trying to do, but now I think I don't :( The rewrite rule that we started with does exactly that, i.e. it rewrites the clients request domain1.com to www.domain1.com. I thought this was what you were trying to do originally. Anyway, now I think you are just trying to create site which has name based virtual hosts, which respond to domainx.com and www.domainx.com so here goes... First you need your main site, let's call it www.domain.com and the ip-address for your site is xxx.xxx.xxx.xxx You create a file 000-domain in your /etc/apache2/sites-enabled (you actually create it in /etc/apache2/sites-available directory and symlink it in the /etc/apache2/sites-enabled). The file is something like this: NameVirtualHost xxx.xxx.xxx.xxx <VirtualHost xxx.xxx.xxx.xxx> ServerAdmin [EMAIL PROTECTED] ServerName www.domain.com DocumentRoot /var/www/ <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/> Options Indexes FollowSymLinks MultiViews AllowOverride None Order allow,deny allow from all </Directory> ErrorLog /var/log/apache2/error.log LogLevel warn CustomLog /var/log/apache2/access.log combined ServerSignature On </VirtualHost> Then you create a file 001-domain1 for your first virtual host <VirtualHost xxx.xxx.xxx.xxx> ServerAdmin [EMAIL PROTECTED] ServerName www.domain1.com ServerAlias domain1.com DocumentRoot /var/www/domain1 <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/domain1> Options Indexes FollowSymLinks MultiViews AllowOverride None Order deny,allow Allow from all </Directory> ErrorLog /var/log/apache2/domain1-error.log LogLevel warn CustomLog /var/log/apache2/domain1-access.log combined ServerSignature On </VirtualHost> Then you create a file 002-domain2 for your second virtual host <VirtualHost xxx.xxx.xxx.xxx> ServerAdmin [EMAIL PROTECTED] ServerName www.domain2.com ServerAlias domain2.com DocumentRoot /var/www/domain2 <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory /var/www/domain2> Options Indexes FollowSymLinks MultiViews AllowOverride None Order deny,allow Allow from all </Directory> ErrorLog /var/log/apache2/domain2-error.log LogLevel warn CustomLog /var/log/apache2/domain2-access.log combined ServerSignature On </VirtualHost> And restart your apache. Now you have three severs, first one is the default if none of the other ones have matching server name for the request. You have your main server files in /var/www directory, the first virtual host files in /var/www/domain1 and the second virtual host files in /var/www/domain2. The virtual servers will respond to domainx.com and www.domainx.com and only for those two variants and nothing gets rewritten. You also have the per server log files in your /var/log/apache2/. Let me know if this is what you are trying to achieve. Simo -- :r ~/.signature
signature.asc
Description: Digital signature