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,013
  • 1
  • 18
  • 30
cfuson
  • 1
  • 1
  • 2
  • 1
    `When I try to access the site via "www.mywebsite.com" it tries to load from https:// 192.xxx.xxx.xxx address` What do you mean by that, where are you seeing the 192 address? Is your application redirecting to that address when you attempt to access it using the domain name? – Shane Madden Dec 08 '15 at 18:02
  • I use FireFox from an external location and when I type in www.mywebsite.com, you can see at the bottom it shows "Connecting to 192.xxx.xxx.xxx – cfuson Dec 08 '15 at 18:32
  • What's the DNS configuration for `www`? Do you have that name configured in your system's hosts file? – Shane Madden Dec 08 '15 at 18:33
  • I have not touched the hosts file for the web server and it has 192.xxx.xxx.xxx computername.domainname.com Note that domainname is our internal domain and not mywebsite.com. – cfuson Dec 08 '15 at 18:38
  • Can you post your https configuration ? – Froggiz Dec 08 '15 at 18:40
  • from which file? – cfuson Dec 08 '15 at 18:42
  • it should be in in a .conf file in site-enabled folder or httpd.conf, i added /etc/hosts configuration in my post – Froggiz Dec 08 '15 at 18:46
  • I dont have a section in my httpd.conf file. just the . – cfuson Dec 08 '15 at 18:48
  • search for *.conf in your Apache2 folder, you may have some other web configuration in site-enabled for example – Froggiz Dec 08 '15 at 18:50
  • none found with – cfuson Dec 08 '15 at 19:05
  • @cfuson So, again, what's your DNS configuration for the `www` name look like? – Shane Madden Dec 08 '15 at 19:10
  • Name=www, type=Alias(CNAME), data=mywebsite.com Name=(same as parent folder), type = Host(A), data=192.xxx.xxx.xxx – cfuson Dec 08 '15 at 19:12
  • I seem to be getting closer - after clearing my browsers cache, it no longer tries to go to 192.xxx.xxx.xxx, instead I just get "Unable to connect" unless i prefix with https:// – cfuson Dec 08 '15 at 19:16
  • Do you have a Listen 80 somewhere ? (maybe Apache2 folder in */port.conf) – Froggiz Dec 08 '15 at 19:41
  • You are a genius - I added the listen 80 to the httpd.conf file and now all is working as it should. thanks a ton for your help\ – cfuson Dec 08 '15 at 19:48
  • Np ! I have added this information to the answer – Froggiz Dec 08 '15 at 21:08

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,013
  • 1
  • 18
  • 30
  • I added using the virtual host as you described. As far as the DNS, we have an internal DNS server and it has a forward lookup zone for mywebsite.com. it has an A record with Name=www and the data is the servers IP address. Are you saying I should remove that and just have an Alias(CNAME) record with Name=www and data=mywebsite.com? – cfuson Dec 08 '15 at 18:29
  • Or can't you just use2 A records (one with www and the other without) ? – Froggiz Dec 08 '15 at 18:30
  • that is what is currently setup. the A name points to the 192.xxx.xxx.xxx address – cfuson Dec 08 '15 at 18:35
  • the Host(A) name points to the 192.xxx.xxx.xxx address and since the A record requires an IP address I created a CNAME record with name=www and data = mywebsite.com – cfuson Dec 08 '15 at 18:41
  • I seem to be getting closer - after clearing my browsers cache, it now longer tries to goto 192.xxx.xxx.xxx, instead I just get "Unable to connect" unless i prefix with https:// – cfuson Dec 08 '15 at 18:49