Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a unique situation I think, google isn't telling me much.

I want to have a way to have a hyperlink in html to simply go to: http://:8081 http://:8080

When the page itself is running on port 80.

This would usually be easy, however this is being developed as a virtual appliance to run offline on our sales teams machines, and as such the IP address will always be different dependant on the machine its running on. I also cannot use DNS for this.

Afaik, it is impossible to have a relative hyperlink to link to another port. I then thought I could perhaps just link to "./site1" and "./site2" and then use mod_rewrite to write those links to the right port.

Does anyone know how to do this? I went do it and got stuck when I realised I wanted to rewrite the URL to a static IP which I can't do! (apache or nginx rewrite rules, or any other solution very welcome!)

share|improve this question
Sorry.. serverfault didn't like my links. That shoudl read: <pre> http://<server_ip>:8081 http://<server_ip>:8080 </pre> – bobinabottle Nov 24 '09 at 18:59
I'm confused by your requirement. If it is always running offline (I assume on the same PC that is offline) then you would want the link to be localhost:8080 for example, localhost would always point to the local machine. – Dave Drager Nov 24 '09 at 19:03
Sorry I should have added that the guest VM is running the webserver (CentOS). The sales guys would access the website from the host (Mac) – bobinabottle Nov 24 '09 at 19:05
I have to admit, I have no idea what you are actually trying to do. If the server is listening on port 80, why are you trying to rewrite to another port? – Michael Graff Nov 24 '09 at 19:08
up vote 0 down vote accepted

Use the hostname that the page requester asked for the page as, and add the port to it. With CGI it's SERVER_NAME, but the details will be dependent on what's doing the rewriting.

share|improve this answer

Thanks for the response pjz, it turns out I was a little confused with ServerName, as I thought it was dependant on DNS.

I did the following:

<VirtualHost _default_:80>
        ServerName offlinewebdemo

        RewriteEngine On
        RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /site1\ HTTP/ [NC]
        RewriteRule ^.*site1$ http://%{SERVER_NAME}:8081/ [R=301,L]

        RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /site2\ HTTP/ [NC]
        RewriteRule ^.*site2$ http://%{SERVER_NAME}:8080/ [R=301,L]

And that worked :-) I then set relative links in the html. I can now click the links correctly, without needing DNS or a static IP.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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