1

I am having trouble getting my htaccess to redirect the website to both www and https... I have tried adding snippets that I have found in previous posts but the best I can get it to do is only redirect correctly on the homepage, not the others...

Here is the full htaccess

order deny,allow
deny from all
allow from env=allowclient
SetEnvIf X-Cluster-Client-Ip 192.88.134.3 allowclient
SetEnvIf X-Cluster-Client-Ip 192.88.135.3 allowclient
SetEnvIf X-Cluster-Client-Ip 185.93.228.3 allowclient
SetEnvIf X-Cluster-Client-Ip 185.93.229.3 allowclient
SetEnvIf X-Cluster-Client-Ip 185.93.230.3 allowclient
SetEnvIf X-Cluster-Client-Ip 192.88.134.0/23 allowclient
SetEnvIf X-Cluster-Client-Ip 185.93.228.0/22 allowclient
SetEnvIf X-Cluster-Client-Ip 192.124.249.0/24 allowclient
SetEnvIf X-Cluster-Client-Ip 199.223.236.179 allowclient
SetEnvIf X-Cluster-Client-Ip 146.148.117.213 allowclient
SetEnvIf X-Cluster-Client-Ip 23.251.134.134 allowclient
SetEnvIf X-Cluster-Client-Ip 178.33.238.180 allowclient
SetEnvIf X-Cluster-Client-Ip 142.4.217.0/24 allowclient
SetEnvIf X-Cluster-Client-Ip 167.114.0.0/24 allowclient
SetEnvIf X-Cluster-Client-Ip 192.99.17.0/24 allowclient
SetEnvIf X-Cluster-Client-Ip 5.196.79.0/24 allowclient
SetEnvIf X-Cluster-Client-Ip 130.211.0.0/16 allowclient
SetEnvIf X-Cluster-Client-Ip 104.155.0.0/16 allowclient

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteRule ^index\.php$ - [L]
RewriteRule ^static/lib/(.*) /wp-includes/$1?p_hide_my_wp=soloshotfirst [QSA,L]
RewriteRule ^file/(.*) /wp-content/uploads/$1?p_hide_my_wp=soloshotfirst [QSA,L]
RewriteRule ^static/ext/(.*) /wp-content/plugins/$1?p_hide_my_wp=soloshotfirst [QSA,L]
RewriteRule ^static/(.*) /wp-content/themes/tc/$1?p_hide_my_wp=soloshotfirst [QSA,L]
RewriteRule ^enfold/(.*) /wp-content/themes/enfold/$1?p_hide_my_wp=soloshotfirst [QSA,L]
RewriteRule ^static_main/(.*) /wp-content/themes/enfold/$1?p_hide_my_wp=soloshotfirst [QSA,L]
RewriteRule ^ajax /wp-admin/admin-ajax.php?p_hide_my_wp=soloshotfirst [QSA,L]
RewriteRule ^wp-content/themes/tc/screenshot\.png|readme\.html|license\.txt|wp-content/debug\.log|wp-includes/$ /nothing_404_404?p_hide_my_wp=soloshotfirst [QSA,L]
RewriteRule ^(((wp-content|wp-includes)/([A-Za-z0-9\-\_\/]*))|(wp-admin/(!network\/?)([A-Za-z0-9\-\_\/]+)))(\.txt|/)$ /nothing_404_404?p_hide_my_wp=soloshotfirst [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>

# END WordPress

<FilesMatch "\.(ttf|otf|woff)$">
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
</IfModule>
</FilesMatch>
1
  • Can't spot any attempts to redirect to a wwwhostname or to use https as protocol. Commented Dec 31, 2015 at 20:24

2 Answers 2

1

Use (after RewriteBase /):

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

Only one redirect with or without www

Sign up to request clarification or add additional context in comments.

Comments

1

Try this.

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

3 Comments

No, first redirect to https and www, and only after to https. You avoid 2 redirect (one for https and after one other for www)
You don't redirect with www, but with your rules, you redirect without www to https and after to https with www... . With mine you redirect with www to https ou without, but only with one rewrite.
And you can't do that with [OR], because you redirect http://www to https://www.www.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.