create an alias for `localhost:8080/` as `www.my-domain.com/`

In ubuntu, I want to create an alias for localhost:8080/ as www.my-domain.com/. So that whenever I type www.my-domain.com/ in URL field, it shows up from localhost:8080/. What is the easiest way to set this up ? Is there any application that could just do this mapping?

In windows, I used to use Fiddler2 to achieve the same goals.


Solution 1:

You can add a /etc/hosts entry like the following:

127.0.0.2   my-domain.com

Make sure to use a lo address unused before.

Then you add an iptables rule to redirect the traffic incoming into 127.0.0.2:8080 to 127.0.0.1:80.

iptables -t nat -A OUTPUT -d 127.0.0.2 -p tcp --dport 80 -j REDIRECT --to-port 8080

Solution 2:

For doing this on firefox, you can install the Redirector add-on. After installing, restart firefox and then go to Tools > Add-ons > Redirector > Preferences.

Click on "New Redirect...". And in the "Include Pattern" field add www.my-domain.com/ or whatever you want the redirection to occur from. And in the "Redirect to" field, add localhost:8000. Type www.my-domain.com/ in the "Example URL" field and click "Test pattern" if you want to confirm it works. If you see this:

redirection successful

You will be able to type www.my-domain.com/ to go to localhost:8000.