7

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.

  • Do you want this to be browser-independent? – jobin Feb 20 '14 at 19:34
  • Possible duplicate: askubuntu.com/questions/26386/renaming-localhost – saiarcot895 Feb 20 '14 at 19:34
  • @saiarcot895: No its not! The OP has given an example for localhost, its not how to rename it. – jobin Feb 20 '14 at 19:36
  • @Jobin: Preferably yes, but browser dependent may also be acceptable. – Rajat Gupta Feb 20 '14 at 19:50
  • @saiarcot895: I also had a look to that question earlier but the answer there doesn't work for port forwarding.. – Rajat Gupta Feb 20 '14 at 19:51
10

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
| improve this answer | |
1

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.

| improve this answer | |
  • anything similar for chrome as well ? – Rajat Gupta Feb 20 '14 at 20:03
  • oops .. that is a redirect solution, not an alias.. sorry I didn't wanted this.. – Rajat Gupta Feb 20 '14 at 20:06
  • @user01: How exactly would it matter? – jobin Feb 20 '14 at 20:07
  • @user01: Did you have a look at the link posted by saiarcot895: askubuntu.com/questions/26386/renaming-localhost? – jobin Feb 20 '14 at 20:12
  • actually it does.. I use domain as alias for localhost while in developemnt mode – Rajat Gupta Feb 20 '14 at 20:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.