Redirect IP Address to Subdomain
Asked by UJ:

After long time using different Atlassian products I have set up subdomains for all of them. Now users can still access with the IP address (e.g. jira: aaa.bbb.ccc.ddd:8080), but you get (of course) an error message because of the wrong base URL. Since some users have stored the IP address in their browser or address book I want to have a redirection to the subdomain:

aaa.bbb.ccc.ddd:8080 -\> jira.mysubdomain.com

I've tried Apache Redirect for that without success:

\<VirtualHost \*:8080\>  
ServerName <http://aaa.bbb.ccc.ddd:8080>  
Redirect 301 / <https://jira.mysubdomain.com/>  
\</VirtualHost\>

Is it possible anyway, because of the reverse proxy? (<https://confluence.atlassian.com/kb/proxying-atlassian-server-applications-753894340.html#ProxyingAtlassianServerapplications-ConnecttoyourapplicationviaaReverseProxyoverHTTP>)

Is there a built in solution for Jira, Confluence or Bitbucket?

system: Ubuntu 18.04 server, latest confluence, jira and bitbucket. SSL and reverse proxy active.


Answers:
author: Thomas Deiler
body: Dear [@UJ](/t5/user/viewprofilepage/user-id/369036) ,

sure this is possible. Follow this [article](https://www.sslshopper.com/apache-redirect-http-to-https.html) and also read the comments.

So long

Thomas

comments: author: UJ
body: Hmm. I don't want to redirect from http **to** https but IP:port **to** domain.  
I also read the comments and nobody describes my case.


author: Thomas Deiler
body: Dear [@UJ](/t5/user/viewprofilepage/user-id/369036) ,

have you tried

```
<VirtualHost aaa.bbb.ccc.ddd:8080>
ServerName http://aaa.bbb.ccc.ddd:8080
Redirect 301 / https://jira.mysubdomain.com/
</VirtualHost>
```

In the end this a redirect from http to https. Just took this snippet from you original post.

So long

Thomas


author: Alexis Robert
body: Hi [@Thomas Deiler](/t5/user/viewprofilepage/user-id/484715) ,

this won't work because users will not hit Apache (see my comment above) as they directly hit Tomcat with 8080 port. Apache only listens on ports 80 and 443, it won't be able to catch anything on 8080 (as it's used by Tomcat for Jira ...).


author: Thomas Deiler
body: Dear [@UJ](/t5/user/viewprofilepage/user-id/369036) ,

[@Alexis Robert](/t5/user/viewprofilepage/user-id/1213386) seems to be right. I recommend to change the port of Jira. For example to 8888. Then also adapt the reverse proxy settings. And add the 8080 with Apache to catch the request and redirect to 443.

Then you can be sure they won't access the old port.

So long

Thomas


author: UJ
body: [@Thomas Deiler](/t5/user/viewprofilepage/user-id/484715)and [@Alexis Robert](/t5/user/viewprofilepage/user-id/1213386) : ah, now I understand why my redirect doesn't work.

Changing the port for Jira is a good idea! I will check this out.


author: UJ
body: Somehow this doesn't really work out. Now I just removed the port from the firewall. Not such an elegant solution but I have spent enough time with it :) Thanks [@Thomas Deiler](/t5/user/viewprofilepage/user-id/484715) and [@Alexis Robert](/t5/user/viewprofilepage/user-id/1213386) for the help!


author: Amit Verma
body: You can simply do this using your htaccess file.

Here is the code to redirect IP to domain

```
RewriteEngine on
RewriteCond %{HTTP_HOST} ^1\.1\.2\.3$
RewriteRule (.*) https://sub.example.com/$1 [L,R=301]
```

Replace ip with your domain ip.

If you want to learn URL rewriting , you can follow this tutorial [https://amitoverflow.com/2021/04/15/htaccess-tutorial-for-beginers/](https://amitoverflow.com/2021/04/15/htaccess-tutorial-for-beginers/ "htaccess tutorial for beginners")


author: Alexis Robert
body: Hi [@UJ](/t5/user/viewprofilepage/user-id/369036) ,

unfortunately you won't be able to use Apache to redirect users, since Apache is probably listening on ports 80 and 443 and your users are reaching port 8080 directly.

You could probably set up an iptable rule however, for example [this post](https://serverfault.com/questions/248851/iptables-block-port-8080-but-not-for-localhost) might help.

Let me know if this works,

--Alexis


Tags: bitbucket

bitbucket-server

confluence-server

jira

jira-server

server