Welcome to WebmasterWorld Guest from 54.146.206.127

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

redirecting to http://IP:port

in .htaccess file?

     
12:52 pm on Feb 26, 2007 (gmt 0)

New User

10+ Year Member

joined:Feb 26, 2007
posts:6
votes: 0


Currently in .htaccess file I've got the following (obviously different IP and port numbers):

RewriteRule ^(.*)$ [255.255.255.0:10255...] [R=301,L]

...and it's not working. The same line works fine for a valid domain name.
My questions:
Does the redirect mod support this kind of forwarding?
Is there any other way of achieving my goal?

Cheers
Adam

11:13 pm on Feb 26, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Is this a publicly-accessible IP address? If not, you're probably looking to implement a reverse proxy -- See the [P] flag for RewriteRule, and also see Apache mod_proxy

Jim

12:46 pm on Feb 27, 2007 (gmt 0)

New User

10+ Year Member

joined:Feb 26, 2007
posts:6
votes: 0


Yes, it's a public address of our router, no restrictions.
1:58 pm on Feb 27, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Hmmm... In that case, it should work for any machine outside the router.

If that's not clear, picture it this way: It is impossible to have a single TCP/IP connection that is both outgoing and incoming from the same machine or router at the same time. If the request is routed to the outside of your router, then there is "nothing out there" -- no "agent" to send the request back into the router and to your server.

Jim

2:35 pm on Feb 27, 2007 (gmt 0)

New User

10+ Year Member

joined:Feb 26, 2007
posts:6
votes: 0


To make my situation clearer:
Our company is based in UK and has a web site hosted in USA. I created a subdomain on our domain through the interface provided by them. Now I want all hits on this subdomain to be redirected to our office router with it's fixed public IP address. This hardware/IP is unrelated to our hosted domain. As we have only one public IP and several machines (including 4 servers) we use private IPs, NAT and NAPT. I think it's a quite common situation. I want to make one of the servers (and more servers in the future) accessible from outside of our office via typing a subdomain URL in a browser. There is already a rule created on our router. It works perfect for other redirections once you type appropriate IP:port address in the browser or other software such as ssh client. The router listens and forwards all hits to his IP on a specified port to one of the internal servers. But for our customers I want a human readable URL not a hard to remember string of numbers! The only thing missing is a redirection on the subdomain host:
[subdomain.domain.co.uk...] -> [IP:port...]
I must say I have limited control over it, e.g. there is no mod_proxy support and all I have is the .htaccess and .htpasswd files.
Thanks
Adam
3:00 pm on Feb 27, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


The devil is in the details... :)

What you are describing should work, so the problem is identifying "What, specifically, does not work?" and "Where, specifically, is the problem occurring?"

The only thing I see wrong is that your rule will drop the "page" part of the URL, and might be better written as


RewriteRule ^(.*)$ http://123.45.67.87:8080[b]/$1[/b] [R=301,L]

to avoid that problem.

Also, if you have no other working mod_rewrite rules in the subdomain's subdirectory .htaccess file, you will need to enable mod_rewrite using the second (and quite possibly both) of the two initial lines here:


Options +FollowSymLinks
RewriteEngine on
#
RewriteRule ^(.*)$ http://123.45.67.87:8080/$1 [R=301,L]

See the mod_rewrite documentation for more info.

Also, use a good HTTP headers checker, such as the "Live HTTP Headers" extension for Firefox/Mozilla browsers, to see what --if any-- response you're getting from the subdomain server. You should be seeing the 301-redirect response as specified in the .htaccess file.

Jim

4:23 pm on Feb 27, 2007 (gmt 0)

New User

10+ Year Member

joined:Feb 26, 2007
posts:6
votes: 0


My .htaccess file:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^#*$!.#*$!.co.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www.#*$!.#*$!.co.uk$
RewriteRule ^(.*)$ [255.255.255.255:10255...] [R=301,L]

This structure works fine, thanks a lot.
Adam

4:37 pm on Feb 27, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Just two potential problems to fix, and two efficiency tweaks:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?xyz\.abc\.co\.uk
RewriteRule (.*) http://255.255.255.255:10255/$1 [R=301,L]

This removes the end-anchor from the hostname pattern -- an alternative is to append "(:[0-9]+)?$" -- to allow for port numbers appended to the hostname, which can occur.

It also handles both the www and non-www hostnames with one RewriteCond.

The literal periods in the domain name should be escaped as shown.

Since ".*" is a greedy pattern and stands alone here, there's no need to anchor it.

Jim

5:43 pm on Feb 27, 2007 (gmt 0)

New User

10+ Year Member

joined:Feb 26, 2007
posts:6
votes: 0


working as well, thanks again