2

Actually my concern was to redirect the both internal and external IP addresses to the domain name and any http://domain traffic to https://domain, which I have achieved by adding these lines in httpd.conf file:

#Redirect IP to domain name

<IfModule rewrite_module>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^172\.1\.20\.4$ [NC,OR]
RewriteCond %{HTTP_HOST} ^83\.101\.140\.185$ [NC]
RewriteRule (.*) http://ict-helpdesk.madanonwovens.com/$1 [R=301,L]
</IfModule>

#Redirect all connections to HTTPS

<IfModule rewrite_module> 
RewriteEngine On 
#Force SSL on all connections 
RewriteCond %{HTTPS} off 
RewriteCond %{REMOTE_HOST} !^127\.0\.0\.1 
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 
</IfModule>

But now I want to redirect https://IP-address to https://domain Because when I write https://IP-address it ask me to add exception and redirect to the page without encryption.

Please Help!

2 Answers2

0

I found this solution: You need to define second virtual host without server name and server alias as *. example:

<VirtualHost *:443>
  ServerAdmin webmaster@localhost
  DocumentRoot /var/www
  ServerAlias *

  <Directory /var/www>
    Options Indexes FollowSymlinks
    AllowOverride None
    Require all granted
  </Directory>

  ErrorLog ${APACHE_LOG_DIR}/error.log
  CustomLog ${APACHE_LOG_DIR}/access.log combined

RewriteEngine on
RewriteRule ^(.*)$ https://our.domain/$1

</VirtualHost>

You will not avoid warning from web browser about insecure connection i think, because your browser ask web server on IP over SSL and cannot check certificate because it is connected with domain, not IP. After connection with web server, it redirect to domain address and certificate can be checked.

-1

Atlast, I aceived this by generating .htaccess file in the application root directory and added the same rules in the file but still it is asking for add exception in the browser and after it the rewrite condition rewrites the domain name over IP address.

Is there any way to automatically redirect to domain name when user typed https://IP-address without adding exception in the browser.

  • 1
    This is not the answer. Please answer your own question by providing the real answer instead of asking another help. You can edit your question. – MaXi32 Aug 18 '19 at 15:29