|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
I am trying to find out howto to rewrite some virtual hosts in apache. I have currentlly configured several virtual hosts on my system for two sites with 2 document roots.
ie.: www.123.com www.234.com www.345.com www.456.com 123.com uses documentroot /docuroot1 456.com uses documentroot /docuroot2 What I would like is to have 234.com and 345.com rewritten to 123.com. So when a user enters http://www.234.com in his browser, the server rewrites it to http://www.123.com and all the links that are used next will also be displayed with www.123.com. I tried to find something about this in the manuals (http://httpd.apache.org/docs/mod/mod_rewrite.html http://www.engelschall.com/pw/apache/rewriteguide/) but all I can find is stuff about rewriting directory structures and that kind of stuff. There is no good example about rewriting domains. Anyone ever done this before? -maarten |
|
#2
|
|||
|
|||
|
you should have followed the link at the bottom of your first URL
![]() http://httpd.apache.org/docs/misc/rewriteguide.html tells you how...
__________________
-- Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more. |
|
#3
|
|||
|
|||
|
rewrite virtual hosts in apache
Well, I tried the suggestions that are mentioned in that manual. I have edited the virtual hosts section of the virtual host I would like to rewrite. So what I am trying to do here is rewrite 123.abc.com to 234.abc.com. I am probably missing something very simple. When I visit http://123.abc.com/ the browser keeps showing 123.abc.com in stead of changing it into 234.abc.com.....
<VirtualHost *> ServerAdmin webmaster@dummy-host.example.com DocumentRoot /usr/local/apache2/htdocs ServerName 123.abc.com ErrorLog logs/dummy-host.example.com-error_log CustomLog logs/dummy-host.example.com-access_log common RewriteEngine on RewriteLog logs/rewritelog.txt RewriteLogLevel 1 RewriteCond %{HTTP_HOST} !^123\.abc\.com [NC] RewriteCond %{HTTP_HOST} !^$ RewriteCond %{SERVER_PORT} !^80$ RewriteRule ^/(.*) http://234.abc.com:%{SERVER_PORT}/$1 [L,R] RewriteCond %{HTTP_HOST} !^123\.abc\.com [NC] RewriteCond %{HTTP_HOST} !^$ RewriteRule ^/(.*) http://234.abc.com/$1 [L,R] </VirtualHost> |
|
#4
|
|||
|
|||
|
The domains in your first post are completely different from your second post. That said, if you must obscure your data, make it consistent.
>> is rewrite 123.abc.com to 234.abc.com Then you don't need a docroot for 123.abc.com. The <VirtualHost> block would then be: Code:
<VirtualHost *> ServerName 123.abc.com RewriteEngine on RewriteRule ^(.*) http://234.abc.com$1 [R,L] </VirtualHost> You also must disable UseCanonicalName by setting it to Off. |
|
#5
|
|||
|
|||
|
Hey, thanks a lot. That works like a charm.
After searching some more and combining some trick that were mentioned in URLrewrite parts, I came up with this: <VirtualHost abc.com> ServerAdmin postmaster@abc.com DocumentRoot /document/root ServerName 127.0.0.1 JkMount /*.jsp ajp13 ErrorLog logs/abc.com-error-log CustomLog logs/abc.com-access_log common RewriteEngine on RewriteLog logs/rewritelog.txt RewriteLogLevel 1 RewriteCond %{HTTP_HOST} ^abc.com$ RewriteRule (.*) http://www.def.com/ </VirtualHost> <VirtualHost www.abc.com> ServerAdmin postmaster@abc.com DocumentRoot /document/root ServerName 127.0.0.1 JkMount /*.jsp ajp13 ErrorLog logs/abc.com-error-log CustomLog logs/abc.com-access_log common RewriteEngine on RewriteLog logs/rewritelog.txt RewriteLogLevel 1 RewriteCond %{HTTP_HOST} ^(.*)\.abc.com$ RewriteRule (.*) http://www.def.com/ </VirtualHost> That one also worked, but now with your suggestion, I could change a 26 line statement into one that only needs 6 lines: <VirtualHost 127.0.0.1> ServerName abc.com ServerAlias abc.com *.abc.com RewriteEngine on RewriteRule ^(.*) http://www.def.com$1 [R,L] </VirtualHost> thank you for your help. maarten |
|
#6
|
|||
|
|||
|
>> into one that only needs 6 lines
Because you are redirecting that entire vhost to elsewhere, therefore, a docroot for that vhost is not even needed. BTW, if you change Code:
RewriteRule ^(.*) http://234.abc.com$1 [R,L] Code:
RewriteRule ^(.*) http://192.168.0.2$1 [P,L] |
|
#7
|
|||
|
|||
|
Hey, that's nice . Thanks!
|-----------| |------------------| WEBA | | |-----------| |---------| | GW | |---------| | |-----------| |------------------| WEBB | |----------| So let's say I have got a leyout like above. WEBA is 10.2.3.1 and WEBB is 10.2.4.1. Now when I install apache with mod_ssl on the gateway, I can have it fetch the pages from WEBA and WEBB for me and present them using HTTPS to my client. Now if I am correct: you can not use this when you are using virtual hosting on WEBA and WEBB right? Because then it would send the user that's before the GATEWAY, directly to an internal IP in stead of proxying... I was wondering about one thing though. Can I also have https://web.abc.com/WEBA send to WEBA and https://web.abc.com/WEBB to WEBB.... maarten |
|
#8
|
|||
|
|||
|
If I understand you correctly, yes, you can run a reverse proxy frontend on your HTTPS vhost while the backend (the proxied host) uses HTTP.
Code:
<IfDefine SSL>
<VirtualHost 12.34.56.78:443>
ServerName warez.domain.com
ServerAdmin webmaster@domain.com
SSLEngine on
SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
SSLCertificateFile /etc/ssl/server.crt
SSLCertificateKeyFile /etc/ssl/private/server.key
SetEnvIf User-Agent ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0
<Files ~ "\.(cgi|shtml)$">
SSLOptions +StdEnvVars
</Files>
RewriteEngine on
RewriteOptions inherit
RewriteCond %{HTTP_HOST} !^warez\.domain\.com$ [NC]
RewriteRule ^(.+) /var/www/htdocs/error.cgi [T=application/x-httpd-cgi,L]
RewriteRule ^/icons/(.+) - [PT,L]
RewriteRule ^(.*) http://192.168.0.6/warez$1 [P,L]
CustomLog /var/log/warez_log log_this env=!dont_log
</VirtualHost>
</IfDefine>
With this, session from public to https://warez.domain.com at 12.34.56.78:443 is encrypted. Say my 12.34.56.78 box also has another NIC with 192.168.0.1. So between 192.168.0.1 and 192.168.0.6, it's unprotected and in cleartext. But there's no security flaw since those are LAN traffic and not sniff'able with my firewall setup. |
|
#9
|
|||
|
|||
|
rewrite virtual hosts in apache
Well, it was partially what I meant. What I was thinking about was redirecting visitors based on the subdirectory they are accessing. An example:
john enters: http(s)://abc.def.com/john and will be browsing to internal host 1 mary enters: http(s)://abc.def.com/mary and will be browsing to internal host 2 or: http(s)://1.2.3.4/john/index.html = http://10.2.3.4/index.html and: http(s)://1.2.3.4/mary/index.html = http://10.2.4.5/index.html maarten |
|
#10
|
|||
|
|||
|
Then you just have to change
Code:
RewriteRule ^(.*) http://192.168.0.6/warez$1 [P,L] Code:
RewriteRule ^/john(.*) http://10.2.3.4$1 [P,L] |
|
#11
|
|||
|
|||
|
rewrite virtual hosts in apache
Never knew it was that simple to use apache for this kind of stuff. Do you know if there is a work arround for virtual hosting? This is all IP based, and if I understand correctly: as soon as you start using domain-names in stead of IP addresses, apache starts redirecting in stead of proxying.
What I am thinking of for example is: Say I have an apache server and an IIS server. The IIS server is hosting 50 domains on 1 IP address. What I would like to do is connect the apache server to the internet and have it act as a reverse proxy for the IIS server. So there is: apache 5.5.5.5 IIS: 10.10.1.1 - www.123.com, www.234.com, .... www.999.com So I probably have to put those 50 domains into apache as well, but how do I get to proxy it to the W2K machine Does IIS know how to react by hostheader? Or does apache replaces that with an IP on rewrite? I am quite surpries by the way that this rewriting is this powerfull. Have quite some new tricks (well for me at least) to try next week.... |
|
#12
|
|||
|
|||
|
The only requirement is that, your Apache must be able to talk to your IIS, and those 50 fake FQDNs MUST be resolvable to Apache and IIS. You may run a DNS server for your LAN or use just the same /etc/hosts file on both boxes.
>> Or does apache replaces that with an IP on rewrite? Like I said, so long as your Apache be able to resolve google.com and yahoo.com, you can change your two lines to be: Code:
RewriteRule ^/google(.*) http://www.google.com$1 [P,L] RewriteRule ^/yahoo(.*) http://www.yahoo.com$1 [P,L] |
|
#13
|
|||
|
|||
|
Great! Hey, thanks for all your help. Going to enable and disable some switches myself now. Let's see what I can make of it.
maarten |
![]() |
| Viewing: Dev Shed Forums > System Administration > Apache Development > rewrite virtual hosts in apache |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|