0

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.

4
  • "when i copied it to Server2, it simply isn't applied." - are .htaccess files and mod_rewrite enabled on server2? "sub1.server1.com" - You use domain1.com in your code, but server1.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.
    – MrWhite
    Nov 6, 2019 at 10:40
  • Yes, they are reffering to the same, i only confused my own placeholder terms. I corrected them tho. However, you led my thoughts in the right direction, so i can now give a solution which i edit into my original post. Thanks a lot! Nov 6, 2019 at 12:24
  • Welcome to Server Fault! Please don't edit your solution into your question. Instead, post an answer and accept it. Otherwise the question will stay as "unanswered" in the system and pop up again and again in the future. Nov 6, 2019 at 12:36
  • Ok, i corrected it. Thanks for the hint. Nov 6, 2019 at 12:38

1 Answer 1

0

I got it working now. I had to add the following VirtualHost entry before my actual "sub1" entry in my 000-default.conf on Server2:

<VirtualHost *:80>
    ServerName domain1.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    <Directory "/var/www/html">
        AllowOverride All
        Allow from All
    </Directory>

</VirtualHost>

The asterisk was important to enable mod_rewrite in all directories and now its finally working. On Server1 i had to use "domain1.com" instead of the asterisk, which was a bit confusing. Thanks for pushing me to the right direction.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .