WordPress Redirige toutes les requêtes HTTP vers HTTPS via .htaccess
-
-
Essayez detracer la redirection: http://redirectdetective.com/Try tracing the redirect: http://redirectdetective.com/
- 1
- 2016-08-22
- jdm2112
-
J'aitesté cela (questionmise àjour avec desinformations supplémentaires) - J'aimême désactivé le cache Google Chromepour éviter desproblèmes comme celui-ci,http://stackoverflow.com/questions/5690269/disabling-chrome-cache-for-website-developmentTested that (updated question with additional info) - I've even disabled Google Chrome cache to avoid issues like this, http://stackoverflow.com/questions/5690269/disabling-chrome-cache-for-website-development
- 0
- 2016-08-22
- Michael Cropper
-
Avez-vousessayé l'inverse?`RewriteCond% {SERVER_PORT}! ^ 433 $`Have you tried the other way arround? `RewriteCond %{SERVER_PORT} !^433$`
- 0
- 2016-08-22
- David
-
Avec la réponse [queje vous ai donnée dans votre questionprécédente] (http://wordpress.stackexchange.com/q/236727/98212),celan'a-t-ilpas résolutous vosproblèmes HTTPS?Oufaites-vous celapour renforcer HTTPS sur votre site Web?With the answer [I gave you in your previous question](http://wordpress.stackexchange.com/q/236727/98212), did that not fix all of your HTTPS issues? Or are you doing to this to reinforce HTTPS across your website?
- 0
- 2016-08-22
- Ethan O'Sullivan
-
Il afaitpour cette question ouimerci.Je veuxtout rangerpour que si quelqu'un accède à la version http du site,il soit 301 redirigé vers https.It did for that question yes thanks. I'm wanting to tidy everything up so that if anyone accesses the http version of the site they are 301 redirected to https.
- 0
- 2016-08-23
- Michael Cropper
-
@MichaelCropper,cela devrait être automatiquementprisen compte lorsque vous avezmis àjour l'URL de lamaisonet du sitetant que vous avez lesparamètrespar défaut `.htaccess` qui ont étégénéréspar WordPress.@MichaelCropper this should be automatically taken care of when you updated the home and site URL so long you have the default `.htaccess` settings that were generated by WordPress.
- 0
- 2016-08-23
- Ethan O'Sullivan
-
C'est étrange.Semble rediriger automatiquement 301 sur lapage d'accueil,maispas sur le reste du site.Voirici,cettepageesttoujours accessible sur HTTP,http://www.michaelcropper.co.uk/contact-me/- Test sur sitepersonnel avant de se déployerpartout.It's odd. Seems to automatically 301 redirect on the homepage, but not on the rest of the site. See here, this page is still accessible on HTTP, http://www.michaelcropper.co.uk/contact-me/ - Testing on personal site before rolling out everywhere.
- 0
- 2016-08-23
- Michael Cropper
-
Assurez-vous d'utiliser `@ EthanJinksO'Sullivan`pour queje sois averti lorsque vous répondezet queje puisse vous répondre rapidement.Jete donneraima réponse ci-dessousBe sure to use `@EthanJinksO'Sullivan` so I get notified when you response and I can get back to you quickly. I'll give you my answer below
- 0
- 2016-08-23
- Ethan O'Sullivan
-
9 réponses
- votes
-
- 2016-08-23
Je vois,lorsque vousentrez un lien vers votrepage autre que votremaison,exemple:
http://www.michaelcropper.co.uk/contact-me
www.michaelcropper.co.uk/contact-me
michaelcropper.co.uk/contact-me
Si
https://
n'estpas dans lepréfixe,le lien HTTP se charge à laplace. Ajoutez ce qui suit dans votre.htaccess
entre labalise<IfModule mod_rewrite.c>
:RewriteCond %{HTTPS} !=on RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]
Si aucunemodification supplémentairen'a été apportée à votre
.htaccess
,cela devrait ressembler à ce qui suit:# 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] # Rewrite HTTP to HTTPS RewriteCond %{HTTPS} !=on RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L] </IfModule> # END WordPress
Dites-moi comment ça sepasse.
I see, when you enter a link to your page other than your home, example:
http://www.michaelcropper.co.uk/contact-me
www.michaelcropper.co.uk/contact-me
michaelcropper.co.uk/contact-me
If
https://
is not in the prefix, the HTTP link loads instead. Add the following into your.htaccess
in between the<IfModule mod_rewrite.c>
tag:RewriteCond %{HTTPS} !=on RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L]
If there were no additional modifications done to your
.htaccess
, it should look like the following:# 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] # Rewrite HTTP to HTTPS RewriteCond %{HTTPS} !=on RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L] </IfModule> # END WordPress
Let me know how it goes.
-
Merci @ EthanJinksO'Sullivan cela afonctionné.Étrangement aussi,j'aitrouvé une autre configuration oùj'avais cefonctionnement qui étaittrès similaire à la configuration d'origine quej'aitestéeet quifonctionnait également cematin `RewriteCond% {SERVER_PORT} 80 RewriteRule ^ (. *) $ Https://www.michaelcropper.co.uk/$1 [R=301,L] `- Sur cettebase,je devrais supposer que quelque chose étaitmisen cache quelquepart.Qui sait avec certitude.Thanks @EthanJinksO'Sullivan this worked. Strangely too, I found another setup where I had this working which was very similar to the original setup I tested which also worked this morning `RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.michaelcropper.co.uk/$1 [R=301,L]` - Based on this I'd have to assume that something somewhere was being cached. Who knows for sure.
- 0
- 2016-08-24
- Michael Cropper
-
J'ai dû réécrire le code après le RewriteBase \.I had to rewrite the code after the RewriteBase \.
- 1
- 2018-10-24
- Harish ST
-
Celan'apasfonctionnépourmoi - les règles https semblent devoir venir avant,afin detravailler avec lespagesintérieures également.Did not work for me - https rules seems to need to come before, in order to work with inner pages too.
- 0
- 2018-11-20
- tishma
-
Comme l'ont dit les autres commentateurs: Vous devez **insérer les deux lignesjuste après `RewriteBase/` **.Dans lapositionindiquée dans la réponse,celane fonctionnera quepour lapage d'accueil.As the other commenters said: You have to **insert the two lines right after `RewriteBase /`**. In the position shown in the answer, it will only work for the frontpage.
- 3
- 2019-09-24
- tanius
-
- 2019-02-17
Ajouter du code dans unfichier .htaccess
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{HTTPS} !=on RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # BEGIN WordPress RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
Add code within a .htaccess file
<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{HTTPS} !=on RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # BEGIN WordPress RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
-
- 2018-09-11
Vouspouvez définir l'en-tête dans .htaccess
<IfModule mod_headers.c> Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains" env=HTTPS </IfModule>
You can set header in .htaccess
<IfModule mod_headers.c> Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains" env=HTTPS </IfModule>
-
Celam'a aidé,alors qu'aucune de ces solutionsn'afonctionné.This helped me, while none of the above worked.
- 0
- 2020-01-07
- Clain Dsilva
-
+1 Cela a l'avantage qu'ilestmoins susceptible deprovoquer un conflit avec les règlesexistantes de `mod_rewrite.c`+1 This has the benefit that it's less likely to cause conflict with existing `mod_rewrite.c` rules
- 0
- 2020-04-27
- Dave A-W
-
- 2018-09-19
essayez ceci dans votre
.htaccess
:RewriteCond %{HTTP:X-Forwarded-Proto} !=https RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R] </IfModule> # END WordPress
try this in your
.htaccess
:RewriteCond %{HTTP:X-Forwarded-Proto} !=https RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R] </IfModule> # END WordPress
-
- 2018-05-28
Ajoutez simplement ceci dans votrefichier .htaccess
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{HTTPS} !=on RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
Just Add this in your .htaccess file
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteCond %{HTTPS} !=on RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
-
uneexplicationpourquoi ce code résoudrait la question d'OPesttoujours agréablesome explanation why this code would solve OP's question is always nice
- 0
- 2018-05-28
- cjbj
-
- 2018-07-19
Si vous utilisez W3 Total Cache,la réponse de @Ethan Jinks O'Sullivanne fonctionnera que si vousplacez la redirection avant lesmods W3 Total Cache dans .htaccess commeindiqué ci-dessous
#BEGIN Rewrite HTTP to HTTPS <IfModule mod_rewrite.c> RewriteCond %{HTTPS} !=on RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L] </IfModule> #END Rewrite HTTP to HTTPS # BEGIN GZIP COMPRESSION ... # END GZIP COMPRESSION # BEGIN DEFLATE COMPRESSION ... # END DEFLATE COMPRESSION # BEGIN W3TC Browser Cache ... # END W3TC Browser Cache # BEGIN W3TC Page Cache core ... # END W3TC Page Cache core # 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
If you are using W3 Total Cache the answer from @Ethan Jinks O'Sullivan will only work if you place the redirect before the W3 Total Cache mods in .htaccess as shown below
#BEGIN Rewrite HTTP to HTTPS <IfModule mod_rewrite.c> RewriteCond %{HTTPS} !=on RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L] </IfModule> #END Rewrite HTTP to HTTPS # BEGIN GZIP COMPRESSION ... # END GZIP COMPRESSION # BEGIN DEFLATE COMPRESSION ... # END DEFLATE COMPRESSION # BEGIN W3TC Browser Cache ... # END W3TC Browser Cache # BEGIN W3TC Page Cache core ... # END W3TC Page Cache core # 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
-
- 2019-06-29
Prenez 10minutespour résoudre leproblème
Ajoutez unfichier de configurationpour votre domaine.
Accédez à centos 7 à
/etc/httpd/conf.d/
,puis créez unfichier de configuration appeléanything.conf
.Mettez le code suivant dessus:
<VirtualHost *:80> ServerName domain.com ServerAlias www.domain.com ServerAdmin [email protected] DocumentRoot /var/www/html <Directory /var/www/html> Options -Indexes +FollowSymLinks AllowOverride All </Directory> ErrorLog /var/log/httpd/example.com-error.log CustomLog /var/log/httpd/example.com-access.log combined </VirtualHost>
Remplacez
example.com
par votre domaine.
Ajoutezensuite le code de réécriture https sur .htaccess,celafonctionnera.:)Toke me 10 minutes to fix the issue
Add a conf file for your domain.
Go to centos 7 at
/etc/httpd/conf.d/
, then create a conf file calledanything.conf
.Put the following code on it:
<VirtualHost *:80> ServerName domain.com ServerAlias www.domain.com ServerAdmin [email protected] DocumentRoot /var/www/html <Directory /var/www/html> Options -Indexes +FollowSymLinks AllowOverride All </Directory> ErrorLog /var/log/httpd/example.com-error.log CustomLog /var/log/httpd/example.com-access.log combined </VirtualHost>
Replace
example.com
with your domain.
Then add the https rewrite code on .htaccess its will work. :) -
- 2019-11-06
Si vousne voulez rien changer sur .htaccess,vouspouvezessayer ceci
add_action('template_redirect', 'redirect_core', 50); add_action('init', 'redirect_core', 50); add_action('wp_loaded', 'redirect_core', 50); function redirect_core(){ if (!is_ssl()) { wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 301); exit(); } }
Ouessayez ceplugin: Redirection HTTPS
If you don't want to change anything on .htaccess you may try this out
add_action('template_redirect', 'redirect_core', 50); add_action('init', 'redirect_core', 50); add_action('wp_loaded', 'redirect_core', 50); function redirect_core(){ if (!is_ssl()) { wp_redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], 301); exit(); } }
Or try this plugin: HTTPS Redirect
-
- 2019-08-13
#BEGIN Rewrite HTTP to HTTPS <IfModule mod_rewrite.c> RewriteCond %{HTTPS} !=on RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L] </IfModule> #END Rewrite HTTP to HTTPS # 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
#BEGIN Rewrite HTTP to HTTPS <IfModule mod_rewrite.c> RewriteCond %{HTTPS} !=on RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L] </IfModule> #END Rewrite HTTP to HTTPS # 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
-
En quoi votre réponseest-elle différente de @ChrisSprague?How is your answer different from @ChrisSprague?
- 1
- 2019-08-13
- nmr
J'aifait celaplusieursfois auparavant,et pourtantje neparvienspas à le refairepour une raisoninconnue.Essayé des solutionsinfinies.Tout ce quej'aiessayéentraîne uneboucle de redirection sansfin.
Quelleest lameilleure optionpour cela?
Mise àjour 1 Voici quelques-unes des chosesessayées;
Et;
Testé dans différentsnavigateurspour éviter lesproblèmes demiseen cache.Toujours rien,juste uneboucle de redirection continue.