Forum Moderators: phranque
The domain: [a.b.c...]
Redirects to: [a.z.c...]
I really know how make that for only one domain but not for a set of subdomains...
It is a heavy and complex code for me to write a RULE for each subdomain, what I'm looking for is only a generic little piece of code. :) thx
Welcome to WebmasterWorld [webmasterworld.com]!
That's a pretty simple application... Have you reviewed the Apache [httpd.apache.org] mod_rewrite and mod_alias documentation? See also the Apache URL Rewriting Guide, linked from the mod_rewrite page.
(By way of explaining this answer, our charter [webmasterworld.com] specifies, that we'll help you get your code working, but not write it for you.)
Jim
Now I show you the code I'm working on:
RewriteEngine on
RewriteCond %{HTTP_HOST} [^.]+\.b\.com$
RewriteRule ([^.]+)\.b\.com(.*) [$1.z.com...]
the problem is that I'm not able to make it work.
I understand that it's a very simple code (I thought that) but my 'newb skill' doesn't let me see the error.
If DNS are ok, what's wrong?
If the URL http://example.com/test/code.html is requested, RewriteRule only "sees" the "test/code/html" in .htaccess, or "/test/code.html" in httpd.conf. It does not see the "example.com" part.
RewriteCond {HTTP_HOST} sees only the "example.com" part, plus any appended port number.
Jim
1 RewriteEngine on
2 RewriteCond %{HTTP_HOST} ^www\.[^.]+\.host\.com$
3 RewriteRule ^(.+) %{HTTP_HOST}$1 [C]
4 RewriteRule ^www\.([^.]+)\.host\.com(.*) /home/$1$2
that is exactly what I'm looking for but without 'www'. I know that code works fine, and I know that if I'm not able to make it
work it's due to my inexperience and understanding of it.
While I analize the code there is no problem until I arrive at line 3. If the hostname and the URl-path must be treated separately
why the line 3 mixes them?
After a lot of think ( and read what [C] means, well I'm newb ) I have reached a conclusion.
the line 2: I write 'www.a.b.com/c' in my window (there is a match)
the line 3: mod-rewrite redirects 'www.a.b.com/c' to 'www.a.b.com/www.a.b.com/c'
the line 4: redirects 'www.a.b.com/c' to '/home/a/c'
Please, If I'm wrong tell me why, and if I'm right tell me too because I'll continue thinking why my new code doesn't still want
to work on my server.
Txen.
HTTP_HOST is not part of the requested URL as seen by RewriteRule, unless you force the hostname into it, as is done in line 3 above. Line 4 then uses the hostname added by line 3.
The solution you have found is more complicated than what is needed.
To redirect all files in domain a.b.c to the like-named files in domain a.z.c: http://a.b.c/d -> http://a.z.c/d, all that is required is a simple two-line ruleset:
RewriteCond ${HTTP_HOST} ^([^.]+\.)?[b]b[/b]\.([^:]+)$
RewriteRule (.*) http://%1[b]z[/b].%2/$1 [R=301,L]
RewriteCond ${HTTP_HOST} ^([^.]+\.)?b\.com
RewriteRule (.*) http://%1z.com/$1 [R=301,L]
Jim
by the way i don't think this is what you have been looking for since this is about virtual hosting of *different* websites, not about the aliasing of one website.
have fun