0

I tried adding to the .htaccess file

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://mywebsite.com/$1 [R=301,:]

I also tried (in the httpd.conf file)

<VirtualHost *:80>
 RewriteEngine on
 ReWriteCond %{SERVER_PORT} !^443$
 RewriteRule ^/(.*) https://www.mywebsite.com/$1 [NC,R=301,L]
</VirtualHost>

When I try to access the site via www.mywebsite.com it tries to load from https:// 192.xxx.xxx.xxx address

I am able to access it via https://mywebsite.com

Any ideas what I am doing wrong or not setting?

Thanks

Froggiz
  • 3,083
  • 1
  • 21
  • 30
cfuson
  • 1

1 Answers1

1

This this the syntax to redirect http to https (you don't need to use all of thoose configuration, use Virtual host or .htaccess, not both):

Using virtual host:

<VirtualHost *:80>
ServerName 192.xxx.xxx.xxx
ServerAlias mywebsite.com
Redirect 301 / https://mywebsite.com/
</VirtualHost>

or

<VirtualHost *:80>
ServerName 192.xxx.xxx.xxx
ServerAlias mywebsite.com
RewriteRule (.*) https://mywebsite.com/$1
</VirtualHost>

Using .htaccess

RewriteCond %{SERVER_PORT} ^80$
RewriteRule .* https://mywebsite.com/%{REQUEST_URI} [R=301,L]

In your case

You might have something else who interact with your redirect, cause it is not normal that the IP is served instead of domain name

Check your DNS configuration to be sure that it serve mywebsite.com instead of the IP

By the way RewriteCond %{SERVER_PORT} 80 will match to all port with 80 in it, so the rule will be applied to 80,800,880,1080,8080, etc ...

in your /etc/hosts you can add:

127.0.0.1 localhost
127.0.0.1 mywebsite.com
127.0.0.1 www.mywebsite.com www

You can even set the server IP instead of 127.0.0.1 for the domain names

If needed you can set Apache to listen on port 80 :

Listen 80
Froggiz
  • 3,083
  • 1
  • 21
  • 30