0

I recently moved to https from http and i have a redirect chain that shows up in safari slowing down the load time of my site.

I've spent several days with bluehost and it seems no one knows/is willing to help re-write to the .htaccess file, it's also possibly not their job either, so fair enough. I've spend several hours myself and I now have a rough understanding but still could use a bit of help.

My preferred domain is https://jambarteambuilding.com

the redirect chain in safari is http://www.jambarteambuilding.com then to https://www.jambarteambuilding.com then to https://jambarteambuilding.com

What im aiming for is

 http://www.jambarteambuilding.com
 http://jambarteambuilding.com
https://www.jambarteambuilding.com

all to redirect to

https://jambarteambuilding.com

also.

My website and wordpress install is housed in a subdirectory called 'clean'. So public_html/clean where you will find wp-admin, wp-content, wp-includes.

my .htaccess file is written so that if you type jambarteambuilding.com the website loads from the clean but you don't see jambarteambuilding.com/clean in the URL only jambarteambuilding.com (which is what i prefer).

So

This is my current .htaccess file.

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^(www.)?jambarteambuilding.com$ 
RewriteCond %{REQUEST_URI} !^/clean/ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /clean/$1 
RewriteCond %{HTTP_HOST} ^(www.)?jambarteambuilding.com$ 
RewriteRule ^(/)?$ clean/index.php [L]

My feeling is that I need to write an [OR] statement after line 2 to capture https://www.jambarteambuilding.com in the conditions. [NC]seems to be missing from line 2 and 7 R=301 seems to be missing form line 6 and 8 line 2 and 7 seem to be duplicated. the jambarteambuilding.com should be jambarteambuilding.com Im guessing that (www.)? means 'with or without www'

Could anyone easily help rewrite this for me!

2 Answers2

0

From this question. Something like this should work...

RewriteCond %{HTTPS} off 
RewriteCond %{HTTPS_HOST} !^jambarteambuilding.com$ [NC]
RewriteRule ^(.*)$ https://jambarteambuilding.com/$1 [L,R=301]

Or, if you are able to modify the Apache VirtualHost file then this would be better...

<VirtualHost *:80>
    ServerName jambarteambuilding.com
    ServerAlias www.jambarteambuilding.com
    Redirect / https://jambarteambuilding.com/
</VirtualHost>
<VirtualHost *:443>
    ServerName jambarteambuilding.com
    ServerAlias www.jambarteambuilding.com
    # ... SSL configuration goes here
</VirtualHost>
sdexp
  • 756
  • 4
  • 18
  • 36
  • thanks for the reply. I'll have to search for the apache virtualhost, it's not something i've looked at before. For rhe rewritecond, Would those 3 lines be in addition to the other 8? – Jimmymacip Jul 24 '18 at 10:12
  • I'd say try putting the 3 new lines at the start after `RewriteEngine on` then remove all the lines you have that mention `%{HTTP_HOST}`. The VirtualHost method isn't mandatory, but for anyone doing Apache administration it's the suggested way to do it. Not to worry if you don't have SSH access. – sdexp Jul 24 '18 at 10:58
  • ok thanks. i've added a summary to your original post. Does that look correct? – Jimmymacip Jul 24 '18 at 11:10
  • I can't see the editing but I'd say back up your `.htaccess` and try it. If anything behaves badly you can always go back to the original `.htaccess`. – sdexp Jul 24 '18 at 13:22
0

This solved it!

RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTPS_HOST} !^jambarteambuilding.com$ [NC]
RewriteRule ^(.*)$ https://jambarteambuilding.com/$1 [L,R=301]
RewriteCond %{REQUEST_URI} !^/clean/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /clean/$1
RewriteRule ^(/)?$ clean/index.php [L]

Thanks All!