---
title: "Password protect a specific URL with .htaccess"
description: "Bu yazıda belirli bir url'ye .htaccess yardımı ile nasıl basic auth ekleyeceğinize değindim."
image: "https://sezer.in/wp-content/uploads/2022/04/htpasswd-apache-htaccess.png"
url: "https://sezer.in/password-protect-a-specific-url-with-htaccess/"
date: "2022-04-19T14:22:25+03:00"
updated: "2022-05-02T23:52:13+03:00"
author: "Sezer Şanlıkan"
lang: "tr"
source: "https://sezer.in/password-protect-a-specific-url-with-htaccess/"
---

# Password protect a specific URL with .htaccess

Öncelikle sayfada kullanacağımız kullanıcı adı ve şifre için htpasswd oluşturalım.

> sezer => Kullanıcı adı

```
htpasswd -c .htpasswd sezer
```

```
New password:
Re-type new password:
Adding password for user sezer
```

Dosyamız oluştu.

```
[root@server home]# ls -la
total 4
drwxr-xr-x.  2 root root  23 Apr 19 14:00 .
dr-xr-xr-x. 17 root root 244 Jan 22 18:27 ..
-rw-r--r--   1 root root  44 Apr 19 14:00 .htpasswd
```

Şimdi .htaccess dosyamızın en üstüne aşağıdaki komutları ekleyelim.

> \- */test/url* kısmını kendinize göre değiştirin.
>
> \- *AuthUserFile* kısmındaki dosya yolunu kendinize göre düzenleyin.

```
SetEnvIf Request_URI ^/test/url auth=1

AuthName "Password Protected"
AuthType Basic
AuthUserFile /home/.htpasswd

Order Allow,Deny
Satisfy any
Allow from all
Require valid-user
Deny from env=auth
```

Hepsi bu kadar.
