0

I want to redirect URL using VirtualHost configuration in Apache using mod_rewrite without changing user browser URL.

i.e if someone access grafana.test.lan:80 they should redirect to http://grafana.test.lan:3000 without user knowledge or URL change.

This is my configuration file :

LoadModule rewrite_module "/etc/httpd/modules/mod_rewrite.so"

<VirtualHost *:80>
 ServerName grafana.test.lan
 RewriteEngine on
 RewriteRule ^(.*) http://grafana.test.lan:3000/$1
</VirtualHost>

any idea how I can do that? I am configuring it on Centos 7.

2 Answers 2

2

You have 2 way to do it:

1. Using mod_proxy

To enable proxy mod, you have to send those commands in bash:

a2enmod proxy
ad2enmod proxy_http

Then by changing your web configuration like this

<VirtualHost *:80>
ServerName grafana.test.lan
ProxyPass / http://grafana.test.lan:3000/
ProxyPassReverse /  http://grafana.test.lan:3000/
</VirtualHost>

Official links: mod_proxy, mod_proxy_http

2. Using mod_rewrite

By changing your web configuration like this

<VirtualHost *:80>
ServerName grafana.test.lan
RewriteEngine on
RewriteRule (.*) http://grafana.test.lan:3000/$1 [P]
</VirtualHost>

Official link: mod_rewrite

1
  • Using the P flag on the RewriteRule (mod_rewrite) also uses mod_proxy.
    – MrWhite
    Apr 13, 2017 at 20:13
-1

You can't do this with a rewrite. You need to use a reverse proxy between the users of the site and the server that's serving up on port 3000. Details are left as an exercise for the author.

1
  • 1
    Can you you please explain how can i do that in reverse proxy. i Am new to it. Dec 22, 2015 at 9:18

You must log in to answer this question.

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