Home › Forums › BulletProof Security Pro › WordPress SSL htaccess code – Rewrite SSL, RewriteCond Server Port
Tagged: htaccess SSL, HTTPS, Rewrite SSL, RewriteCond, SSL, SSL Vhost, WordPress SSL, WordPress SSL htaccess code
- This topic has 123 replies, 22 voices, and was last updated 10 months, 1 week ago by nehakakar kakar.
-
AuthorPosts
-
Paulin HalenriaParticipant
[Topic has been merged into this relevant Topic]
I made search on the website and didn’t find the correct code. I’d like to merge those codes but no idea how to perform correctly.# Rewrite www to non-www RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC] RewriteRule ^(.*)$ http://example.com/$1 [R=301,L] RewriteRule ^index\.php$ - [L] # WP REWRITE LOOP START RewriteEngine On RewriteBase / RewriteCond %{HTTPS} !=on RewriteCond %{SERVER_PORT} ^80 RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L] RewriteRule ^index\.php$ - [L] Indeed, I want my website been only reachable by https://example.com So I need to redirect all requests from http://example.com http://www.example.com https://www.example.com
And the second part, no idea if it could work… I’m using Polylang to have my website bilingual using two different domains.So, I need for the same website, have the requests from
http://example2.com http://www.example2.com https://www.example2.com to https://example2.com
But as already said, no idea if such a setup will be possible or not…. My first idea would be
# Rewrite everything like a pro RewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC] RewriteRule ^(.*)$ https://example.com/$1 [R=301,L] RewriteRule ^index\.php$ - [L] RewriteCond %{HTTP_HOST} ^www\.example2\.com$ [NC] RewriteRule ^(.*)$ https://example2.com/$1 [R=301,L] RewriteRule ^index\.php$ - [L]RewriteCond %{HTTPS} !=on RewriteCond %{SERVER_PORT} ^80 RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L] RewriteRule ^index\.php$ - [L]
Thanks
CedricAITpro AdminKeymaster@ Paulin – The code you are looking for is here: http://forum.ait-pro.com/forums/topic/wordpress-ssl-htaccess-code-rewrite-ssl-rewritecond-server_port/#post-7233
Ruud van der VeerParticipantHi,
I’m completely new here; I hope this is te right place for posting my questing. First: thanks for this great Pro-version I bought last Friday.
My question: see the topic title. Those redirects I made with
RewriteEngine On RewriteCond %{HTTPS} !=on RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
in the .httaccess file. I experienced a lot with it in BP Pro, but noting was successful. And I do have problems with understanding English. Would you be so kind to explain it to me step by step, please?
Thanks in advance,
Ruud
AITpro AdminKeymaster@ Rudd Van Deer – See this reply in this same forum topic for instructions on how to do that.
http://forum.ait-pro.com/forums/topic/wordpress-ssl-htaccess-code-rewrite-ssl-rewritecond-server_port/#post-7233rafaelmagicParticipantLoad Balancers and SSL Redirect
If Apache is behind a Load Balancer , Pound, HaProxy, Nginx.
Then your requests coming from the load balancer arrive over HTTP to Apache, so the HTTPS variable is set to OFF. Therefore, .htacess is reading HTTPS OFF from the server.
However, Apache Server does have a SSL variable called HTTP_X_FORWARDED_PROTO that can be used.
#WP REWRITE LOOP START for Load Balancers RewriteCond %{HTTP:X-Forwarded-Proto} !https RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
or
#WP REWRITE LOOP START- For Load Balancers RewriteEngine on RewriteCond %{HTTP:X-Forwarded-Proto} !https RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
Directions:
WordPress General Settings:
WordPress Address (URL)https://www.your-domain-name.com
Site Address (URL)https://www.your-domain-name.com
1. Copy this .htaccess code below to this BPS Root Custom Code text box: CUSTOM CODE WP REWRITE LOOP START: Add www to non-www/non-www to www code here
2. Click the Save Root Custom Code button.
3. Go to the BPS Security Modes page and click the Root Folder BulletProof Mode Activate button.PaulParticipant[Topic has been merged into this relevant Topic]
I am currently using the following to send index.htm to the root .co.ukRewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^mysite\.co\.uk$ [NC] RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R,L] RewriteRule ^index\.htm$ / [R,L]
I am going to move to ssl and was wondering what i needed to add to this and also what i would need to redirect all pages from http to https?
In above would i just add an s to any http like
RewriteEngine On RewriteBase / RewriteCond %{HTTPs_HOST} ^mysite\.co\.uk$ [NC] RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R,L] RewriteRule ^index\.htm$ / [R,L]
Would this do the http to https bit on a like for like
RewriteEngine On RewriteCond %{HTTPS} off RewriteRule (.*) https://%{SERVER_NAME}/%$1 [R,L]
AITpro AdminKeymaster@ Paul – See this reply in this same forum topic for examples of SSL/HTTPS htaccess code and how/where to add it to BPS Custom Code (or just generally in an htaccess file that is not a BPS htaccess file): http://forum.ait-pro.com/forums/topic/wordpress-ssl-htaccess-code-rewrite-ssl-rewritecond-server_port/#post-7233 Since you are rewriting a index.htm file instead of an index.php then be sure to change index.php to index.htm in your htaccess code that you use/create.
PaulParticipantThanks so am i right in thinking this would do both?
# WP REWRITE LOOP START RewriteEngine On RewriteBase / RewriteCond %{HTTPS} !=on RewriteCond %{SERVER_PORT} ^80 RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L] RewriteRule ^index\.htm$ - [L]
Changed the .php to .htm
AITpro AdminKeymasterI should have asked these questions first: Are you just trying to redirect the index.htm file to the home page of this site? Is the index.htm file under a WordPress installation folder/website? Is this website a separate HTML website?
PaulParticipantOK.
one of my WordPress sites was better suited to not being a wordpress site so i made it a “normal” htm website.
Initially it was not redirecting the index.htm to .co.uk inmstead i could access .co.uk/index.htm too but this solved thatRewriteEngine On RewriteBase / RewriteCond %{HTTP_HOST} ^mysite\.co\.uk$ [NC] RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R,L] RewriteRule ^index\.htm$ / [R,L]
I now would like to make the whole site SSL over https so wanted to redirect everything from http to https and still have code above doing its job on SSL server.
Hope that makes some sense?
AITpro AdminKeymasterOk then the code you posted in your previous reply should work fine or you may need to alter it slightly by changing the RewriteRule to:
RewriteRule ^index\.htm$ / [R,L]
. Try the code you posted in your previous reply and that does not work then try changing the RewriteRule.PaulParticipantOk thanks, i,ll give both a try
# WP REWRITE LOOP START RewriteEngine On RewriteBase / RewriteCond %{HTTPS} !=on RewriteCond %{SERVER_PORT} ^80 RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L] RewriteRule ^index\.htm$ / [R,L]
and
# WP REWRITE LOOP START RewriteEngine On RewriteBase / RewriteCond %{HTTPS} !=on RewriteCond %{SERVER_PORT} ^80 RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L] RewriteRule ^index\.htm$ - [L]
My host gave for the redirect but i,ll try that last 😉
RewriteCond %{HTTPS} on RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC] RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
dtyler1ParticipantMy site is no longer directing all traffic to use the
https://www.domain.com
version of my website. I’ve followed the instructions here testing both code snippets and neither of them are working now (new update to BPS Pro?).AITpro AdminKeymaster@ dtyler1 – While I was logged into your site and looking at the API server error issue/problem, I noticed that you were not using any HTTPS/SSL htaccess code so I added it in BPS Custom Code. If that HTTPS/SSL htaccess code is causing a problem on your site then remove it, but after adding the HTTPS/SSL htaccess code I checked your site and everything was working fine. Also remove any/all HTTPS/SSL htaccess code that you have added to BPS Custom Code.
dtyler1ParticipantI appreciate the code added, but for some unknown reason traffic from http:// is not being redirected to https://
-
AuthorPosts
- You must be logged in to reply to this topic.