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

4
  • Sorry.. serverfault didn't like my links. That shoudl read: <pre> http://<server_ip>:8081 http://<server_ip>:8080 </pre> Nov 24, 2009 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. Nov 24, 2009 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) Nov 24, 2009 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? Nov 24, 2009 at 19:08

2 Answers 2

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.

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .