Rewrite URL Domain Name when IP address used

apache-2.2ip addressportredirectrewrite

My apache home server listens for HTTP requests on an alternate port (port 8080), but I would like to let users type my domain name (example.com) without having to specify the port.

So far I've accomplished this through my DNS provider who redirects any requests to www.example.com or example.com to http://123.456.789.001:8080

This is a problem because though it works, users get an ugly number in their URL bar. What I would like to do is rewrite 123.456.789.001:8080 to example.com

I've tried reading http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html, but I'm no expert at URL writing and what I've come up with (and which obviously doesn't work) is:

RewriteEngine on
RewriteCond %{HTTP_HOST} =123.456.789.001
RewriteRule ^(.*) example.com/$1

which I placed in my httpd.conf file.

Best Answer

In your situation, you can't achieve what you want. There is 3 solutions (in order of "goodness").

  1. Ask your ISP to open port 80.

  2. Get a server somewhere and configure it with a reverse proxy (with Apache or something else).

  3. Instead of a redirection, use a frame to "encapsulate" your page.