.htaccess 加密Apache,禁用特定目录的https

h9a6wy2h  于 2023-02-09  发布在  Apache
关注(0)|答案(1)|浏览(123)

我使用ubuntu,apache和letsencrypt。我想禁用一个目录的https。
这是我的. htaccess现在:

RewriteEngine On
RewriteBase /

#HTTP TO HTTPS
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

domain.nl should redirect to https://domain.nl . (As it does now) http://domain.nl/keuken (or http://domain.nl/keuken/keuken.php is also ok) should just be http.
我不能让它工作。
我尝试了stackoverflow的几个解决方案,但要么它什么也不做,要么我得到了许多重定向。

00jrzges

00jrzges1#

我找到了答案,问题中的.htaccess与此无关,我修改了virtualhost配置文件:000-/etc/apache 2/sites中的默认.conf-可用于:

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port t$
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html

    <Directory /var/www/html>
    AllowOverride All
    </Directory>

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/keuken(/|$) [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

如果我是正确的,这意味着除了/keuken之外的所有内容都被重定向到https。

相关问题