Forum Moderators: phranque

Message Too Old, No Replies

name change and move to https

         

ipco

10:21 pm on Feb 22, 2018 (gmt 0)

10+ Year Member



I have a site that originally had a name change http://www.exa-mple.com to http://www.example.com
using
RewriteEngine On
RewriteRule (.*) http://www.example.com/$1 [R=301, L]


I now want to redirect http://www.exa-mple.com to https://www.example.com
Would this be the correct code to use? Just add the 's'
RewriteEngine On
RewriteRule (.*) https://www.example.com/$1 [R=301, L]

or does it need something else?

thanks

[edited by: phranque at 10:25 pm (utc) on Feb 22, 2018]
[edit reason] unlinked urls [/edit]

phranque

10:29 pm on Feb 22, 2018 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



that should handle things on the exa-mple.com server.

you should also have a http-to-https redirect on the example.com server.

lucy24

10:31 pm on Feb 22, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, that's fine.

I assume the two domains live in different places--that is, requests for Old Domain don't pass through the htaccess or <Directory> section meant for New Domain--because otherwise you would need a RewriteCond to prevent infinite loops. If your existing rule works, then all is good.

Psst! If you need to specify more than one hostname, you can say example.org, example.net, example.xyz and so on.

ipco

11:53 pm on Feb 22, 2018 (gmt 0)

10+ Year Member



Thank you both. I will test it out on the morrow.

ipco

5:00 pm on Feb 23, 2018 (gmt 0)

10+ Year Member



Ok, the SSL is installed and I can access all pages however only the Home page and those pages with forms show the green padlock. All others show the info icon.

This was before changing any code on htaccess. When I did make a change I get an internal error.

So do I actually need to add this code?

Incidentally, when I started this thread I had not looked at the online htaccess I was just prepping from an offline copy. It appears the original redirect is missing. There is also extra code - Cache Control - that was not there prior so I'm thinking the host may have made some changes for whatever reason. BTW, this is not my site, I'm just helping someone.

lucy24

9:34 pm on Feb 23, 2018 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Your original question was about redirecting from another site--example.org, let's say--to example.com. Does example.com itself have a canonicalization redirect? If you've already got one for incorrect www requests, you only need to add a second RewriteCond for HTTPS.

How are the links within example.com coded? If it has absolute links, like http://www.example.com/pagename.html, you need to change all occurrences of http to https. But it's much better to change them all to site-absolute links beginning in / (single slash). In some rare situations you'd need to begin with // meaning "continue with the same protocol", but for humans this is superfluous. (Once a browser is using a particular protocol, it will stay there unless explicitly told to change.)

When I did make a change I get an internal error.
Tell us more. What, exactly, does the error say? If it's a 500-class error such as an infinite loop, your site's error logs should give more information.

Edit: Does the site include any third-party content? Mixed protocols--an https page using some http content--tend to make browsers unhappy. Most often this happens when your site incorporates material from an outside source, such as analytics or fonts or ads.

ipco

12:45 am on Feb 24, 2018 (gmt 0)

10+ Year Member



Hi Lucy24,
what I was trying to say originally was the site was first named http://www.exa-mple.com The owner then bought a new domain name http://www.example.com Same name but without the hyphen. He got the host to redirect http://www.example.com to http://www.exa-mple.com.

I designed the original site so had the original files (.htaccess)

This week I was asked to set up SSL and redirect http to https - hence the questions.

I finally got the host to do the redirects and all is now ok but still not sure where they did the redirects as they are not in the htaccess file.

Anyway, all is now good and I really appreciate the all help from you and phranque.

[edited by: phranque at 2:25 am (utc) on Feb 24, 2018]
[edit reason] Unlinked URLs for clarity [/edit]

phranque

5:30 am on Feb 24, 2018 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



I finally got the host to do the redirects and all is now ok but still not sure where they did the redirects as they are not in the htaccess file.

these directives are probably in that site's VirtualHost container in the server config file (which is typically named httpd.conf or similar) but in a shared hosting environment this file would typically be in a location unseen by the site owner.

ipco

5:52 pm on Feb 24, 2018 (gmt 0)

10+ Year Member



Ah, That explains it. thank you Phranque