2

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!)

bobinabottle
  • 579
  • 2
  • 7
  • 19
  • Sorry.. serverfault didn't like my links. That shoudl read:
    http://:8081
    http://:8080
    
    
    – 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 http://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

2 Answers2

1

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.

pjz
  • 10,595
  • 1
  • 32
  • 40
0

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.

bobinabottle
  • 579
  • 2
  • 7
  • 19