Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to config Apache2 to redirect URL

I am trying to config url redirect in Apache. I have tried some approaches and nothing works. Can someone tell me the solution of this as it doesn't seem too difficult.

I am going to redirect request from:

https://myhost/configuration/jmx-console

to:

http://myanohterhost/jmx-console

This is a https to http re-direct.

Can someone point me to the right direction?

Many thanks!

like image 680
Kevin Avatar asked Jan 04 '11 16:01

Kevin


2 Answers

You could use the RedirectMatch directive to force Apache to send the user someplace else:

RedirectMatch 301 ^(.*)$ http://www.anotherserver.com$1

See the following:

http://httpd.apache.org/docs/2.4/mod/mod_alias.html#redirectmatch

http://en.wikipedia.org/wiki/URL_redirection#HTTP_status_codes_3xx

like image 125
Brian Lacy Avatar answered Sep 29 '22 00:09

Brian Lacy


The normal way to do this would be the following, in the configuration of the current server (or virtual host) `myhost':

Redirect /configuration/jmx-console http://myanohterhost/jmx-console

Edit: According to your comment, it looks like you can do it using one of the following techniques:

1. mod_proxy, using a reverse proxy setup

Simply map the remote server's urls to a local url:

ProxyPass /configuration/jmx-console http://myanohterhost/jmx-console
ProxyPassReverse /configuration/jmx-console http://myanohterhost/jmx-console

2. mod_rewrite using the proxy throughput feature

RewriteRule ^configuration/jmx-console(.*)$ http://myanohterhost/jmx-console$1 [P]

There can be some caveats in using reverse proxying like this, I recommend you to read thoroughly http://httpd.apache.org/docs/2.2/en/mod/mod_proxy.html to see the various options available when using reverse proxying.

like image 40
SirDarius Avatar answered Sep 29 '22 00:09

SirDarius