Abob
Abob

Reputation: 760

How to redirect a domain to a different IP if accessed by a specific port?

I was wondering how I could redirect a sub domain I own (such as mydomain.dx.am) to another external IP address it is accessed by a specific port.

in other words, if you type in this domain, it takes you to the hosted website that is directly attached to the domain (the host is AwardSpace). However, if you access this domain through a specific port (such as 25565 through minecraft), it redirects you to a different external IP (XX.XX.XX.XX). I have tried other services (like NO-IP and free ones), but they don't work for SUBDOMAINS that you already OWN and for redirection only on SPECIFIC PORTS.

I don't want all ports of the subdomain to redirect to a diffferent external IP address, just 1 specific port

Is there any online service or specific way of doing this? What could I do to the .htaccess file to create this redirect?

I have access to the files of the site/host, and to the .htaccess (directly on the file or automated through the host). I can't seem to find acccess to the DNS Zone file and changing the nameservers is really glitchy and fails most of the time for an unaquired reason...if there is some way to do this with what I have avaliable then please let me know! Thanks!

Here is my current .htaccess file (has no problems):

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

Upvotes: 4

Views: 2195

Answers (1)

Evan
Evan

Reputation: 457

This will allow you to redirect based on the incoming port, but assumes that apache is listening on all ports (replace {PORT} with the port you want to have redirected):

RewriteEngine On
RewriteCond  %{SERVER_PORT} ^{PORT}$
RewriteRule ^(.*)$ http://www.redirect.com [L, R=301]

Answer partially pulled from .htaccess redirect to error page if port is not 80

Upvotes: 1

Related Questions