Wordpress: Force HTTPS using .htaccess - wordpress

Problem
Using .htaccess to force HTTPs on my Wordpress site does not work
Tried solution
On my Wordpress site I have the following .htaccess code
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
But to force using HTTPs I'am trying to replace it with this code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} mydomain\.dk [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mydomain.dk/$1 [R,L]
</IfModule>
Result
The website is no longer working (here is the website response):
This page isn’t working
www.mydomain.dk redirected you too many times.
Try clearing your cookies.
ERR_TOO_MANY_REDIRECTS
Questions
Why can't I force using HTTPs on my Wordpress website?
What can I do to make it work?
Best regards, Henning

Before trying the surggested solutions - I tried to change the URL in the Wordpress settings to HTTPS and now it works.
Thanks for taking the time to answer my question, I was just about to try the Really Simple SSL plugin.

If your web server is running Apache, you can redirect all HTTP traffic to HTTPS by returning to the default .htaccess configuration and than adding the following code to your .htaccess file.
This is also the recommended method for redirecting WordPress to Apache:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
However, probably the easiest way to implement HTTPS on your WordPress site would be to install the following plugin:
https://wordpress.org/plugins/really-simple-ssl/

Related

Sitemap not redirecting to HTTPS

Need a little help, I have a website and I have activate SSL to that,
Everything is on SSL except the sitemap page, it’s automatically redirecting to http:// mode rather than https mode.I have to type https manually to view sitemap page in https mode.
For this I am having search console error.Search console can read sitemap but it’s showing http error.How to redirect http to https automatically.Here’s my .htaccess code though.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I am using yoast SEO.
You have to enable HTTPS. I thought Yoast would do that for you. It could be browser cache?
Try adding this to the top of your .htaccess file:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

Wordpress site reverted from https... links broken

A site new to me as of today is broken. It is a wordpress site that the client tried to convert to HTTPS by themselves and it broke. They then tried to undo the work and go back to non-s version.
this has worked with one exception. The site is trying to redirect scripts to the SSL version.
For example trying to access this:
http://example.com/wp-includes/js/jquery/jquery.js?ver=1.12.4
is redirecting to this:
https://www.example.com/js/jquery/jquery.js?ver=1.12.4
(not the real domain.. obv)
Can anybody advise on how to fully revert?
If it helps, the Security Cert was purchase through Namecheap. The hosting is GoDaddy, and they attempted to follow the instructions here: https://designmodo.com/wordpress-https/
** edit **
SSL has been reinstalled, and it doesn't appear to be the problem. Something is redirecting scripts, removing the "wp-includes" from the url
the htaccess
# BEGIN GD-SSL
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_USER_AGENT} ^(.+)$
RewriteCond %{SERVER_NAME} ^example\.com$ [OR]
RewriteCond %{SERVER_NAME} ^www\.example\.com$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
Header add Strict-Transport-Security "max-age=300"
</IfModule>
# END GD-SSL
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Wordpress save a lot of content and settings in the database, try installing this plugin Velvet Blues Update URLs to find-replace in your database the old values https://example.com with http://example.com some plugins save their own cache, so you probably need to go into a file browser and delete their cache folders.
If that doesn't work double check that your .htaccess is not redirecting your http traffic to https.

Cpanel/WHM server can not redirect wordpress site from http to https

I received my certificate through Comodo and installed it through cPanel. It shows up on my browser when I go to the url, but I am unable to get the content of the webpage as I get a 302 redirect loop. I changed my htaccess file to
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.org/$1 [R,L]
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
within the wordpress admin editor, I changed my website from http to https.
Could you please modifies the https rule in .htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
and also go to wordpress setting and chnage the domain redirection
http://example.com to https://example.com
Try the following code to redirect from http to https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.example.org/$1 [R,L]
create a new .htaccess file with the default rules of wordpress >>
In Cpanel redirects options , configure a permanent redirect from http to https with or without www >> you may also need to use a wordpress plugin that apply the proper ssl security to the images and the posts
and then check.

Why am I getting a redirect loop with Wordpress htaccess file?

I'm trying to do a site-wide redirect from http to https for my Wordpress, and I'm trying to follow this tutorial - https://blog.nraboy.com/2014/12/force-https-pages-wordpress-site/
This seems to work for them, but when I follow it, I get a message saying the website is performing in a way that will never complete (or redirect).
My htaccess file currently looks like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Can anyone please help me identify what's causing the redirect loop and how to fix it? I've put it into various testers, which seem to run through it fine. I have no plugins running, and can't figure out what's causing the loop.
I typically add the custom rewrite rules above the default WP ones.
<IfModule mod_rewrite.c>
RewriteEngine On
# Rewrite non www. to www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Rewrite HTTP 2 HTTPS
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
# BEGIN WordPress
...
As you can see both rules redirect to HTTPS (the first one is applied only if non www. though).
Whenever a request is starting with https://www. the standard WP rulez (which you have posted and which are kept below in your .htaccess file) are applied as wanted.

Website Has too many Redirect Loop

Everyone,
i have my ssl certificate installed on https://www.copierextravaganza.com but my actual domain the website runs is on https://copierextravaganza.com ... to make my ssl visible i used 301 redirect by modifying htaccess ... after implementing the code, whenever i open the website it does not load up and shows error website has too many redirects ..
is there some error in the htaccess code below ?
my website is on wordpress
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^copierextravaganza\.com$ [NC]
RewriteRule ^$ https://www.copierextravaganza.com/ [R=301,L]
RewriteRule ^author/(privacy)/?$ /$1 [R=301,L,NC]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Please advice thanks
Abhishek
I think if the site_url option (see settings/general in the wordpress dashboard) is set to http://domain.com and you access it from http://www.domain.com then it will 301 redirect you to http://domain.com. You're effectively forcing the site to redirect you back to http://www.domain.com, causing a loop. The best thing to do would be to either change your site url to http://www.domain.com, or get SSL certification for the domain without the www

Resources