Forum Moderators: phranque
i have following setup: my users are in /var/www/virtual and i have diffrent domains there.
so for example user1.domain.com is in /var/www/virtual/user1.domain.com
As it is now (without mass virtual hosting) - i can also call www.user1.domain.com and it will direct me to /var/www/virtual/user1.domain.com
I dont know how to do it with mod_vhost_alias to make both www.user1.domain.com and user1.domain.com go to /var/www/virtual/user1.domain.com :(
I also dont know how to do it using mod_rewrite..
With mod_vhost_alias i tried VirtualDocumentRoot /var/www/virtual/%2+ , it works ok for www.domain.com but is not working for request for domain.com becouse it will look for virtual/com.
%0 doesnt work either, but for requests with www.
mod_rewrite is pretty hard, i made something like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*) %{HTTP_HOST}$1 [C]
RewriteRule ^www\.(.*) /$1 [L]
it works for sites with www, and i thought that maybe if i turn on also vhost_alias and set it to %0, VirtualDocumentRoot will take care about requests without WWW and mod_rewrite with WWW, but it doesnt work that way, somehow mod_vhost changes something so mod_rewrite is going for endless loop :(
I'm trying to get it done for 2 weeks, and im kinda tired. Anyone has any sugesstions?
i repeat: i have users in /var/www/virtual, like this
user1.domain.com
domain4.edu
user22.domain.com
user22.domain.edu
for example of course.. and i just want them to work with both www.something and just something.
i also have subdomains inside those domains. i have them in a way of user123.domain.com/subdomain.user123.domain.com
If you want people going to www.user.example.com to be redirected to user.example.com, then this should do the trick, assuming your using an .htaccess file:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} ^www\.([^.]+\.example.com)
RewriteRule (.*) [%1...] [R=301,L]
In an httpd.conf file, then the last rule would lack on of the slashes:
RewriteRule (.*) [%1$1...] [R=301,L]
Chad
something like [httpd.apache.org...]
so i think can't redirect them to any other [,...] becouse there is no documentroot set, and apache will not know what to do with it. i have to redirect reqests to specific directories.
so request for [user.domain.com...] and www.user.domain.com will go to /var/www/virtual/user.domain.com
i have many domains and many users to it shouldnt be using RewriteMap
last rule i tried is this one (without lvl 2 subdomain support tho, yet. i mean without user.domain.com/subdomain.user.domain.com - i will try to add it later)
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC] #this one will match everything but www i think
RewriteCond %{REQUEST_URI}!%1 #this one is my pathethic try to stop endless looping, but it doesnt help
RewriteRule ^(.*) /%1$1 [L] #this one should look for /var/www/user.domain.com/index.html for example, but it doesnt work :( it is making endless loop.
i just want it to show apache where are my virtualhosts files, without use of apache.conf, becouse it grew too big.
this is my actual , it works ok for requests user.domain.com or domain.com or www.user.domain.com or www.domain.com and so on, but if i add some specific uri, it fails (second RewriteCond stops it from rewriting probably)
So i need to make it better so it will stop endless loops (why is it happening by the way? i read mod_rewrite documentation and i couldnt find a word about it) but not stop my urls :)
next thing will be user.domain.com/subdomain.user.domain.com