Home URL rewriting in VirtualHost causes 403 Forbidden
Reply: 1

URL rewriting in VirtualHost causes 403 Forbidden

Basj
1#
Basj Published in 2018-02-13 12:10:20Z

My frontend server is handled by Apache 2.4.

I would like that when accessing http://198.51.100.13/site1/, it automatically redirects the traffic to my server's port 1001 like this:

<VirtualHost *:80>
ServerName 198.51.100.13
<Directory "/">
Require all granted
</Directory>

RewriteEngine On
RewriteRule ^/site1(.*)$ http://localhost:1001$1 [P,L]
RewriteRule ^/site2(.*)$ http://localhost:1002$1 [P,L]
RewriteRule ^/site3(.*)$ http://localhost:1003$1 [P,L]
</VirtualHost>

Problem: I get this error when opening http://198.51.100.13/site1/:

403: Forbidden
You don't have permission to access /areallybigpage on this server.

On the other hand, if I do http://198.51.100.13:1001/, it works (there is a Python serveron port 1001, but this is not important for this question).

How to solve this?

Basj
2#
Basj Reply to 2018-02-13 13:20:01Z

The solution is:

<VirtualHost *:80>
ServerName 198.51.100.13
RewriteEngine On
RewriteRule ^/site1(.*)$ http://localhost:1001$1 [P,L]
RewriteRule ^/site2(.*)$ http://localhost:1002$1 [P,L]
RewriteRule ^/site3(.*)$ http://localhost:1003$1 [P,L]
</VirtualHost>

but don't forget to do:

a2enmod proxy  
a2enmod proxy_http       # I forgot this one!
a2enmod proxy_wstunnel   # mandatory if using websockets
service apache2 restart
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 1.061607 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO