# htaccess + htpasswd

**URL:** <https://forum.shopware.com/t/htaccess-htpasswd/55215>\
**Category:** Administration\
**Created:** [18. September 2018 um 09:14 UTC](https://forum.shopware.com/t/htaccess-htpasswd/55215 "2018-09-18T09:14:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zauberP](https://avatars.discourse-cdn.com/v4/letter/z/da6949/32.png) [@zauberP](https://forum.shopware.com/u/zauberP)\
**Post date:** [18. September 2018 um 09:14 UTC](https://forum.shopware.com/t/htaccess-htpasswd/55215/1 "2018-09-18T09:14:13Z")

</div>

&nbsp;Hallo!

Ich probiere seit längerem meinen Shop nur per Passwort zugägnlich zu machen. Leider wird meine htaccess inklusive htpasswd nicht akzeptiert. So sieht meine htaccess aus:

```
RewriteEngine on
AuthType Basic
AuthName "My Protected Area"
AuthUserFile /var/www/xy/xy/www/.htpasswd
Require valid-user

#RewriteBase /shopware/

# Https config for the backend
#RewriteCond %{HTTPS} !=on
#RewriteRule backend/(.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteRule shopware.dll shopware.php
RewriteRule files/documents/.* engine [NC,L]
RewriteRule backend/media/(.*) media/$1 [NC,L]

RewriteCond %{REQUEST_URI} !(\/(engine|files|templates|themes|web)\/)
RewriteCond %{REQUEST_URI} !(\/media\/(archive|banner|image|music|pdf|unknown|video)\/)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ shopware.php [PT,L,QSA]

# Fix missing authorization-header on fast_cgi installations
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

    # Restrict access to VCS directories
    RedirectMatch 404 /\\.(svn|git|hg|bzr|cvs)(/|$)

    # Restrict access to root folder files
    RedirectMatch 404 /(autoload\.php|composer\.(json|lock|phar)|README\.md|UPGRADE-(.*)\.md|CONTRIBUTING\.md|eula.*\.txt|\.gitignore|.*\.dist|\.env.*)$

    # Restrict access to shop configs files
    RedirectMatch 404 /(web\/cache\/(config_\d+\.json|all.less))$

    # Restrict access to theme configurations
    RedirectMatch 404 /themes/(.*)(.*\.lock|package\.json|\.gitignore|Gruntfile\.js|all\.less|node_modules\/.*)$

# Staging environment
#SetEnvIf Host "staging.test.shopware.in" SHOPWARE_ENV=staging

# Development environment
#SetEnvIf Host "dev.shopware.in" SHOPWARE_ENV=dev
#SetEnv SHOPWARE_ENV dev

DirectoryIndex index.html
DirectoryIndex index.php
DirectoryIndex shopware.php

# Disables download of configuration

    # Deny all requests from Apache 2.4+.
    
          Require all denied
    

    # Deny all requests from Apache 2.0-2.2.
    
        Deny from all
    

# Enable gzip compression

    AddOutputFilterByType DEFLATE text/html text/xml text/plain text/css text/javascript application/javascript application/json application/font-woff application/font-woff2 image/svg+xml

    
        ExpiresActive on
        ExpiresDefault "access plus 1 month"
    

    
        Header append Cache-Control "public"
        Header unset ETag
    

    FileETag None

# Match generated files like:
# 1429684458_t22_s1.css
# 1429684458_t22_s1.js

    
        Header set Cache-Control "max-age=31536000, public"
    

    
        ExpiresActive on
        ExpiresDefault "access plus 1 year"
    

# Disables auto directory index

    Options -Indexes

    Options -MultiViews

# php_value memory_limit 256M
# php_value max_execution_time 120
# php_value upload_max_filesize 20M
   php_flag phar.readonly off
   php_flag magic_quotes_gpc off
   php_flag session.auto_start off
   php_flag suhosin.session.cryptua off
   php_flag zend.ze1_compatibility_mode off
   php_value always_populate_raw_post_data -1

# AddType x-mapp-php5 .php
# AddHandler x-mapp-php5 .php

    Header append X-Frame-Options SAMEORIGIN

```

Die htpasswd liegt somit genau neben der htaccess. Mache ich irgendeinen Fehler?

---

<div class="post-metadata">

**Author:** ![Murmeltier](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/murmeltier/32/16126_2.png) [@Murmeltier](https://forum.shopware.com/u/Murmeltier)\
**Post date:** [18. September 2018 um 09:52 UTC](https://forum.shopware.com/t/htaccess-htpasswd/55215/2 "2018-09-18T09:52:51Z")

</div>

**.htaccess:**

```
##################
# PASSWORT SCHUTZ
##################
AuthUserFile /your/path/to/your/.htpasswd
AuthName "My-protected-Area"
AuthType Basic
require valid-user

```

Pack das ganz oben rein in Deine .htaccess. Das _"IfModule mod\_rewrite.c_" und _„RewriteEngine on“_ lässt Du bitte weg!

Falls Du Probleme mit dem richtigen Pfad hast, benutze mal sowas hier:

```
Dein Pafd zu diesem Ordner: " . $dir . "";
echo "Dein Pfad zu Deiner.htpasswd: " . $dir . "/.htpasswd" . "";
?>

```

Diesen PHP Code einfach in eine Texteditor kopieren und die Datei z.B. als pfad.php speichern. Dann schmeisst Du diese Datei in den Ordner, wo Deine zwei Dateien&nbsp;(.htaccess & .htpasswd) drin sind.

Dann einfach im Browser aufrufen:

**[www.deinedomain.de/pfad.php](http://www.deinedomain.de/pfad.php)**

---

<div class="post-metadata">

**Author:** ![Patrick\_Muenster](https://avatars.discourse-cdn.com/v4/letter/p/87869e/32.png) [@Patrick\_Muenster](https://forum.shopware.com/u/Patrick_Muenster)\
**Post date:** [20. April 2019 um 10:49 UTC](https://forum.shopware.com/t/htaccess-htpasswd/55215/3 "2019-04-20T10:49:40Z")

</div>

> Pack das ganz oben rein in Deine .htaccess. Das&nbsp;_"IfModule mod\_rewrite.c_" und&nbsp;_„RewriteEngine on“_&nbsp;lässt Du bitte weg!

&nbsp;

Bei mir funktioniert das auch mit der RewriteEngine.  
Aber vielen Dank für den Tip mit dem PHP Code!&nbsp;Ich hab schon erfolglos versucht, irgendwie in den Templates PHP zu schreiben.
