I am trying to move a part of my website to an external server. I want this part to be accessible through a subdomain, while still being able to apply RewriteRules (doesn't matter whether thats done by .htaccess or Apache2-.conf files, any method is acceptable for me)
I got:
Server1 with IP 1.1.1.1 and DNS entry "domain1.com"
Server2 with IP 2.2.2.2 and no DNS entry
The target directory on Server2 is "/var/www/html/sub1/"
Whenever someone requests anything like "sub1.domain1.com" it should be proxied/redirected to "2.2.2.2/sub1/". All the other subdomains shall remain on Server1.
So i started with defining a VirtualHosts entry on Server1 saying:
<VirtualHost sub1.domain1.com:80>
ServerName sub1.domain1.com
ProxyPass / http://2.2.2.2/sub1/
ProxyPassReverse / http://2.2.2.2/sub1/
</VirtualHost>
And this works to redirect anything being requested through "sub1.domain1.com" to the Server2's DocumentRoot "/var/www/html/sub1/" (while i dont't know how it knows that this is the DocumentRoot - i didn't define it) but my .htaccess rules stopped working.
On Server1 i had a .htaccess file saying something like:
RewriteEngine on
RewriteBase /sub1
RewriteRule ^aaa$ aaa.php?$1 [QSA,L]
RewriteRule ^bbb$ bbb.php?$1 [QSA,L]
RewriteRule ^ccc$ ccc.php?$1 [QSA,L]
And that worked perfectly, but when i copied it to Server2, it simply isn't applied.
So i tried to move all the ruleset to the VirtualHost entry on Server1 like this:
<VirtualHost sub1.domain1.com:80>
ServerName sub1.domain1.com
ProxyPass / http://2.2.2.2/sub1/
ProxyPassReverse / http://2.2.2.2/sub1/
<Directory "/var/www/html/sub1">
AllowOverride All
Allow from All
RewriteEngine on
RewriteBase /sub1
RewriteRule ^aaa$ aaa.php?$1 [QSA,L]
RewriteRule ^bbb$ bbb.php?$1 [QSA,L]
RewriteRule ^ccc$ ccc.php?$1 [QSA,L]
</Directory>
</VirtualHost>
But it still isn't applied.
The final goal is to redirect requests like "http://sub1.domain1.com/aaa/(...)" to "http://sub1.domain1.com/aaa.php?(...)", while getting all those data from Server2's "/var/www/html/sub1/(...)/" directory.
.htaccess
files and mod_rewrite enabled on server2? "sub1.server1.com" - You usedomain1.com
in your code, butserver1.com
in your description - are these referring to the same? ".htaccess file saying something like" - how "like"? The$1
backreference in those directives is superfluous.