0

I have used this code in my .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^silkgifts.co.uk
RewriteRule (.*) https://www.silkgifts.co.uk/$1 [R=301,L]

it directs my HTTPS non-www to the HTTPS www site also it directs the HTTP non-www to the HTTPS www site. However, it is not directing the HTTP www to the https www.

I also put in this code to try and solve the problem:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

which worked in Google Search Console but when testing on other sites it said there was an endless chain of redirects so I removed it.

Can anyone tell me where I am going wrong?


EDIT: Current .htaccess file:

AddHandler php56-script .php .php5

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"
</IfModule>
## EXPIRES CACHING ##

RewriteEngine On
RewriteCond %{HTTP_HOST} ^silkgifts.co.uk
RewriteRule (.*) https://www.silkgifts.co.uk/$1 [R=301,L]

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
MrWhite
  • 12,647
  • 4
  • 29
  • 41
sue
  • 1
  • 1
    Please use the [formatting tools](https://serverfault.com/editing-help) to make your post readable. – Sven Jul 12 '17 at 09:46
  • You also need to show these directives in context. Where are these directives placed in your `.htaccess` file? "which worked in google search console but when testing on other sites it said there was an endless chain of redirects" - What other sites are you testing this on? You test it on your site by checking the HTTP response headers, period. No additional tools are required. – MrWhite Jul 12 '17 at 13:34
  • AddHandler php56-script .php .php5 ## EXPIRES CACHING ## ExpiresActive On ExpiresByType image/jpg "access plus 1 year" ExpiresByType image/jpeg "access plus 1 year" ExpiresByType image/gif "access plus 1 year" ExpiresByType image/png "access plus 1 year" ExpiresByType text/css "access plus 1 month" ExpiresByType application/pdf "access plus 1 month" ExpiresByType text/x-javascript "access plus 1 month" ExpiresByType application/x-shockwave-flash "access plus 1 month" ExpiresByType image/x-icon "access plus 1 year" – sue Jul 13 '17 at 09:17
  • ExpiresDefault "access plus 2 days" ## EXPIRES CACHING ## RewriteEngine On RewriteCond %{HTTP_HOST} ^silkgifts.co.uk RewriteRule (.*) https://www.silkgifts.co.uk/$1 [R=301,L] RewriteEngine On RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] – sue Jul 13 '17 at 09:19
  • the above worked in google console - on a couple of other sites one being GTmetrix it said it couldn't be tested because of the endless chain of redirects – sue Jul 13 '17 at 09:22
  • You need to be more specific. What URL were you requesting that supposedly generated this "endless chain of redirects"? How is the SSL cert managed? There's nothing wrong with the code you posted - that's just a standard redirect. However, depending on how the SSL cert is managed, it could be a problem. – MrWhite Jul 14 '17 at 14:20

0 Answers0