Post by genegrin » Wed Oct 03, 2018 4:30 am

Strange canonical URLs problem
When I type https://www.mysite.com, https:// mysite.com, http://www.mysite.com or https:// mysite.com into my browsers I see this https://www. mysite.com/ Yes, it’s ok.
But Siteliner accessed the site using both https://www. mysite.com/ and https:// mysite.com/. Siteliner received the same content, but different HTTP codes: 200 and 301 respectively.
Seositechecker suggests putting this code in my .htaccess file to fix stuff.
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
My current code is;
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.mysite.com/$1 [R,L]
Do you have any idea on that issue, please?
Thank you.

Active Member

Posts

Joined
Wed Jun 08, 2011 3:00 am

Post by MarketInSG » Wed Oct 03, 2018 8:41 am

You will need to setup .htaccess redirection to either the www or non-www website, depending on how you've installed OpenCart. You can use the .htaccess codes you've pasted above, but some minor changes will be needed to have it point to the correct website. Alternatively, you can use the below.

After

Code: Select all

RewriteBase /
Add

Code: Select all

RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


User avatar
Guru Member

Posts

Joined
Wed Nov 16, 2011 11:53 am
Location - Singapore

Post by genegrin » Wed Oct 03, 2018 10:30 pm

Thank you, MarketInSG.
Please take a look at this code;
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.%{HTTP_HOST}/$1 [R=301]
RewriteRule ^(.*)$ https://www.mysite.com/$1 [R,L]

What's wrong there?

Active Member

Posts

Joined
Wed Jun 08, 2011 3:00 am

Post by EvolveWebHosting » Thu Oct 04, 2018 11:51 am

genegrin wrote:
Wed Oct 03, 2018 10:30 pm
Thank you, MarketInSG.
Please take a look at this code;
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.%{HTTP_HOST}/$1 [R=301]
RewriteRule ^(.*)$ https://www.mysite.com/$1 [R,L]

What's wrong there?
You have 2 rewrite rules and I would suggest trying MarketinSG suggested rules. You can put a # before each line of your existing rules to temporarily disable them while you try the new rules.

Opencart Hosting Plans, Domain Registration, Microsoft and Google Email and More
Visit our website for great deals and most importantly, fast and friendly support - www.evolvewebhost.com


User avatar
Active Member

Posts

Joined
Fri Mar 27, 2015 11:13 pm
Location - Denver, Colorado, USA

Post by genegrin » Fri Oct 05, 2018 11:53 pm

MarketInSG's code works. A lot of thanks!

Active Member

Posts

Joined
Wed Jun 08, 2011 3:00 am

Post by genegrin » Mon Oct 08, 2018 12:21 am

Different tools show the different results. How is it possible?
For example, Siteliner still accessed my site using both https://www. and https:// . Siteliner received the same content, but different HTTP codes: 200 and 301 respectively.

Active Member

Posts

Joined
Wed Jun 08, 2011 3:00 am

Post by genegrin » Mon Oct 08, 2018 7:44 pm

It must be "example.com" to "www.example.com" and then that gets redirected to "https:www.example.com".
What's the code? Suggest please.

Active Member

Posts

Joined
Wed Jun 08, 2011 3:00 am

Post by ADD Creative » Tue Oct 09, 2018 6:44 pm

The correct way to also be compatible with HSTS would be to redirect to https then to www. Try the code below. Notice the E=HTTPS flag, which ensures that only https requests are redirected to www.

Code: Select all

RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule .* https://www.example.com/$1 [E=HTTPS,R=301,L]

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by genegrin » Wed Oct 10, 2018 1:30 am

How do you test your sites for URL Canonicalization Issues, please?
Google and these tools didn’t find canonicalization problems with my site:
SeoSiteCheckup,
Seoreviewtools,
seoprofiler,
coderseo.
However, varvy.com/tools/redirects shows this.

Attachments

2018.png

2018.png (39.34 KiB) Viewed 1454 times


Active Member

Posts

Joined
Wed Jun 08, 2011 3:00 am

Post by ADD Creative » Wed Oct 10, 2018 3:48 am

I just check manually using the web browsers network inspect tool. You could do it all in one step using something like the code below. However some security scanners (such as https://observatory.mozilla.org/) will flag this up as being a redirect to a different host, preventing HSTS for being set for the domain. https://infosec.mozilla.org/guidelines/ ... directions

Code: Select all

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule .* https://www.example.com/$1 [R=301,L]

www.add-creative.co.uk


Expert Member

Posts

Joined
Sat Jan 14, 2012 1:02 am
Location - United Kingdom

Post by genegrin » Thu Oct 11, 2018 5:38 am

OK. Thank you for your help, guys.

Active Member

Posts

Joined
Wed Jun 08, 2011 3:00 am
Who is online

Users browsing this forum: No registered users and 274 guests