Création fichier .htaccess : protection un seul fichier php
... / Création fichier .htacces...
BMPCreated with Sketch.BMPZIPCreated with Sketch.ZIPXLSCreated with Sketch.XLSTXTCreated with Sketch.TXTPPTCreated with Sketch.PPTPNGCreated with Sketch.PNGPDFCreated with Sketch.PDFJPGCreated with Sketch.JPGGIFCreated with Sketch.GIFDOCCreated with Sketch.DOC Error Created with Sketch.
Question

Création fichier .htaccess : protection un seul fichier php

by
CarineG
Created on 2019-06-02 13:14:24 (edited on 2024-09-04 12:24:10) in Hébergement Web-old

Bonjour,

Je souhaite créer un fichier htaccess et htpasswd pour protéger l'accès à un seul de mes fichiers.
J'ai suivi les recommandations ovh mais malgré cela, rien ne fonctionne.

Comment puis-je protéger mon fichier "toto.php" dont l'url est du type :
www.blabla.com/index.php?action=toto ?

Merci pour votre coup de pouce!


8 Replies ( Latest reply on 2019-06-02 14:13:16 by
kyodev
)

> rien ne fonctionne.

concrètement, il se passe quoi?

---

ce n'est pas un fichier toto que tu nous montres,
c'est index, autrement dit le listage du répertoire

.htaccess:
```text
AuthName "Identification requise"
AuthType Basic
AuthUserFile "/home/login/.htpasswd"
Require valid-user
```
dans la racine du site `www`

---

.htpasswd
```text
.htpasswd
# pass: 123
test:CJdhlwz1J/W5k
```
au-dessus de la racine

essaye ça fonctionne

Déjà, merci pour ta réponse! Tu as placé ton htaccess dans ton dossier "login" ?

et concrètement, il ne se passe rien : j'accède à ma page tableauBordAdmin comme les autres pages

non, `login` est la valeur que tu vois dans ton manager Ovh ou dans fileZilla:
https://i.imgur.com/6sB8MXw.png

ça correspond à l'identifiant Ftp

OK...mon htpasswd, je le mets ici :

et mon htaccess ici ?

Je veux protéger uniquement le fichier tableauBordAdmin.php donc dans mon htaccess je fais : en début de fichier?

> j'accède à ma page tableauBordAdmin comme les autres pages

alors le serveur Web ne comprend même pas qu'il y a une restriction

voir ton .htaccess

---

remarque, ton mot de passe doit être chiffré
http://aspirine.org/htpasswd.html
md5 ou bcrypt

---

oui, .htpasswd est très bien là, pour commencer, après tu adapteras

---

ton .htaccess est bien s'il est à côté de index.php
idem tu adapteras plus tard

--

pour la protection d'un fichier, on verra APRÈS