@MBodunov

Авторизация через .htaccess?

На сайте сделал авторизацию с использованием модуля апача auth_form_module через .htaccess
В .htaccess прописано
Session On
SessionCookieName session path=/
SessionMaxAge 86400
#SessionCryptoPassphrase secret
AuthFormProvider file
AuthName "authenticationform"
AuthType form
AuthUserFile www/path_to_domains/login/passwords
AuthFormFakeBasicAuth On
ErrorDocument 401 "/log/aulogin.html" 
Require valid-user
<Files "/log/aulogin.html">
Allow from all
</Files>
ErrorDocument 404 /errdoc.php
#RequestHeader set X-Remote-User expr=%{REMOTE_USER}
#   Кеширование #
<IfModule mod_expires.c>
    ExpiresActive on

    ExpiresDefault "access plus 1 month"

    # cache.appcache needs re-requests in FF 3.6 (thanks Remy ~Introducing HTML5)
    ExpiresByType text/cache-manifest "access plus 0 seconds"

    # html
    ExpiresByType text/html "access plus 0 seconds"

    # XML
    ExpiresByType text/xml "access plus 0 seconds"
    ExpiresByType application/xml "access plus 0 seconds"

    # RSS
    ExpiresByType application/rss+xml "access plus 1 hour"

    # Favicon
    ExpiresByType image/x-icon "access plus 1 week"

    # Картинки
    ExpiresByType image/gif "access plus 1 month"
    ExpiresByType image/png "access plus 1 month"
    ExpiresByType image/jpeg "access plus 1 month"
    ExpiresByType image/jpg "access plus 1 month"

    # HTC файлы  (например css3pie)
    ExpiresByType text/x-component "access plus 1 month"

    # Нестандартные шрифты сайта
    ExpiresByType application/x-font-ttf "access plus 1 month"
    ExpiresByType font/opentype "access plus 1 month"
    ExpiresByType application/x-font-woff "access plus 1 month"
    ExpiresByType image/svg+xml "access plus 1 month"
    ExpiresByType application/vnd.ms-fontobject "access plus 1 month"

    # CSS и javascript
    ExpiresByType text/css "access plus 1 year"
    ExpiresByType application/javascript "access plus 1 year"

</IfModule>

# Cache-Control браузера
<ifModule mod_headers.c>
    # 30 дней
    <filesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$">
    Header set Cache-Control "max-age=2592000, public"
    </filesMatch>
    # 30 дней
    <filesMatch "\.(css|js)$">
    Header set Cache-Control "max-age=2592000, public"
    </filesMatch>
    # 2 дня
    <filesMatch "\.(xml|txt)$">
    Header set Cache-Control "max-age=172800, public, must-revalidate"
    </filesMatch>
    # 1 день
    <filesMatch "\.(html|htm|php)$">
    Header set Cache-Control "max-age=172800, private, must-revalidate"
    </filesMatch>
</ifModule>


<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

    ############################################################################
    #### Убираем повторяющиеся слеши (/) в URL                              ####
    ############################################################################
    RewriteCond %{REQUEST_URI} ^(.*)/{2,}(.*)$
                #Проверяем, повторяется ли слеш (//) более двух раз.
    RewriteRule . %1/%2 [R=301,L]
                #Исключаем все лишние слеши.



  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_FILENAME} !-s
  RewriteCond %{REQUEST_FILENAME} !-l
  RewriteRule ^(.+)$ /index.php?%{QUERY_STRING} [L]
  # RewriteRule ^(.+)$ /errdoc.php?%{QUERY_STRING} [L]
</IfModule>

php_flag register_globals off
php_flag magic_quotes_gpc off

php_value display_errors 1
php_value error_reporting 2047

При разработки использовал локальный сервер OpenServer на котором всё отлично работало.
Механизм такой: из подкаталога открывается форма в подкатологе \log\ после чего файлом router.php запускается файл \login\index.php который прописывает разные куки.
При переносе на внешний хостинг авторизация не проходит. Выходит ошибка
Unauthorized
This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.

Additionally, a 401 Unauthorized error was encountered while trying to use an ErrorDocument to handle the request.
  • Вопрос задан
  • 698 просмотров
Пригласить эксперта
Ответы на вопрос 2
shambler81
@shambler81 Куратор тега htaccess
www/path_to_domains/login/passwords - нужен полынй путь от корня
Ответ написан
Комментировать
@dodo512
Только что попробовали: оказывается если включить php в режиме модуля, то авторизация проходит, а если как CGI то не работает

Для режима CGI можно в .htaccess добавить
CGIPassAuth on
httpd.apache.org/docs/2.4/mod/core.html#cgipassauth
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы