title: Apache httpd.conf for redirecting ip to hostname
body: <p>I have external IP and hostname configured for my machine.</p>
  
  <p>Inside the application, I am using only the domain names to access the APIs. So when i try to access my APIs through IP address, it shows 302 Moved temporarily error.
  So, for request(for Homepage) that hits the server with IP address, It should redirect to hostname. </p>
  
  <p>That is, when user hits <a href="https://XX.XX.XX.XX/main">https://XX.XX.XX.XX/main</a> it should be redirected to <a href="https://ayz-abc.mysite.com/main">https://ayz-abc.mysite.com/main</a></p>
  
  <p>For this I tried using the redirect in httpd.conf of apache. </p>
  
  <pre><code>&lt;VirtualHost XX.XX.XX.XX&gt;
  
  DocumentRoot "/var/www/html"
  #ServerName ayz-abc.mysite.com/
  
   # Other directives here
   RewriteEngine On
   RewriteRule /.* https://ayz-abc.mysite.com/ [R]
  
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>I have also tried with the following</p>
  
  <pre><code>&lt;VirtualHost *.portnum&gt;
  DocumentRoot "/var/www/html"
  RewriteEngine On
  RewriteCond %{HTTPS} on
  RewriteRule  https://XX.XX.XX.XX/main https://ayz-abc.mysite.com/main [R=301,L]
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>Plsssss help me. </p>