【问题标题】:Apache 2.4 LogLevel and rewrite is ignoredApache 2.4 LogLevel 和重写被忽略
【发布时间】:2020-06-22 23:20:30
【问题描述】:

我试图了解为什么我尝试记录重定向和重写在我的配置中失败。我已将“LogLevel debug rewrite:trace6”添加到我的虚拟域配置中,但它没有反映在下面显示的 error_log 中。

我也遇到了重定向问题。我可以用同样的方式记录它们以找出它们似乎被忽略的原因吗?

我想将所有对https://example.com/download.html 的请求重定向到https://example.com/resource-center,并且只有下面的第三个有效。但是,我想确保只有根目录下的 /download.html 有效,而不是 /folder/download.html。我该怎么做?

  Redirect 301 ^/download.html    /resource-center
  Redirect 301 ^download.html    /resource-center
  Redirect 301 /download.html    /resource-center

这些重定向出现在我的配置的包含文件中。

我已在此处包含了我的全部配置,因为我不确定需要哪些部分来帮助解决此问题。

这是 fedora32 上的 httpd-2.4.43-1.fc32.x86_64。

ServerTokens Prod
ServerSignature Off
<VirtualHost 222.111.222.111:443>
  ServerName example.com
  ServerAlias example.com engage.example.com www.example.com support.example.com infocenter.example.com store.example.com updates.example.com
  ServerAdmin gdadmin@example.com
  DocumentRoot /var/www/www.example.com-443/html/
  ScriptAlias /cgi-bin/ /var/www/www.example.com-443/cgi-bin/
  ErrorLog /var/www/www.example.com-443/logs/error_log
  CustomLog /var/www/www.example.com-443/logs/access_log timing
  LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\" %T/%D %I/%O/%B H:%H U:%U gd443 s:%s V:%V v:%v" timing
  CustomLog "/var/www/www.example.com-443/logs/cached-requests.log" timing env=cache-hit
  CustomLog "/var/www/www.example.com-443/logs/uncached-requests.log" timing env=cache-miss
  CustomLog "/var/www/www.example.com-443/logs/revalidated-requests.log" timing env=cache-revalidate
  CustomLog "/var/www/www.example.com-443/logs/invalidated-requests.log" timing env=cache-invalidate
  LogLevel debug rewrite:trace6
  LogLevel error ssl:warn
  SuexecUserGroup guardian guardian
  HostnameLookups off
  RewriteEngine on
  RewriteCond %{HTTP_HOST} ^infocenter.example.com$
  RewriteRule ^ https://example.com/cloud-email-security? [L,R=301]
  RewriteCond %{HTTP_HOST} ^store\.example\.com$
  RewriteRule ^ https://example.com/cloud-email-security? [L,R=301]
  RewriteCond %{HTTP_HOST} !^example\.com$ [NC]
  RewriteRule ^ https://example.com%{REQUEST_URI} [NE,R=301,L]
  RewriteCond %{QUERY_STRING} ^list=
  RewriteRule /eng/                     https://example.com/?   [R=301,L]
  RewriteRule /advisories/              https://example.com/?   [R=301,L]
  KeepAliveTimeout 120
  Timeout 120
  ProxyTimeout 120
<IfModule mod_log_config.c>
  CustomLog "|/var/www/html/apache_pipelogger" "%v %p %m %B %D %s"
</IfModule>
  SecStatusEngine On
  <IfModule !mod_php5.c>
    <IfModule !mod_php7.c>
      SetEnvIfNoCase ^Authorization$ "(.+)" HTTP_AUTHORIZATION=$1
  
      <FilesMatch \.(php|phar)$>
          SetHandler "proxy:unix:/run/php-fpm/example.sock|fcgi://localhost"
      </FilesMatch>
    </IfModule>
  </IfModule>
  <Directory "/var/www/www.example.com-443/html">
    AllowOverride all
    Options +FollowSymLinks +Includes +ExecCGI
    DirectoryIndex index.html index.php
  Include /etc/httpd/conf.d/example-old-links.htaccess
  </Directory>
  SSLEngine on
  Header always set Strict-Transport-Security "max-age=15768000"
  Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure
  Header always set X-FRAME-OPTIONS "SAMEORIGIN"
  Header always set X-XSS-Protection "1; mode=block"
  Header always set X-Content-Type-Options "nosniff"
  SSLCertificateKeyFile /etc/letsencrypt/privkey.pem
  SSLCertificateFile /etc/letsencrypt/cert.pem
  SSLCertificateChainFile /etc/letsencrypt/fullchain.pem
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
   <IfModule mod_mime.c>
    AddType application/x-javascript .js
    AddType text/css .css
   </IfModule>
   <IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/css application/x-javascript text/x-component text/html text/plain text/xml application/javascript
    <IfModule mod_setenvif.c>
        BrowserMatch ^Mozilla/4 gzip-only-text/html
        BrowserMatch ^Mozilla/4.0[678] no-gzip
        BrowserMatch bMSIE !no-gzip !gzip-only-text/html
    </IfModule>
    </IfModule>
    Header append Vary User-Agent env=!dont-vary
</VirtualHost>
<VirtualHost 222.111.222.111:80>
  ServerName example.com
  ServerAlias example.com engage.example.com www.example.com support.example.com infocenter.example.com store.example.com updates.example.com
  ServerAdmin gdadmin@example.com
  ErrorLog /var/www/www.example.com-443/logs/error_log
  CustomLog /var/www/www.example.com-443/logs/access_log timing
  LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-agent}i\" %T/%D %I/%O/%B H:%H U:%U gd80 s:%s V:%V v:%v" timing
</VirtualHost>
SSLProtocol             all -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite          ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256
SSLHonorCipherOrder     on
SSLCompression          off
SSLSessionTickets       off
SSLUseStapling          on
SSLStaplingResponderTimeout 5
SSLStaplingReturnResponderErrors off
SSLStaplingCache        shmcb:/var/run/ocsp(128000)

【问题讨论】:

    标签: apache .htaccess redirect mod-rewrite


    【解决方案1】:

    您的配置中有两个 LogLevel 指令

    LogLevel debug rewrite:trace6
    LogLevel error ssl:warn
    

    第二个覆盖第一个。调试时注释第二条指令。

    重定向

    Redirect 301 /download.html    /resource-center
    

    对我来说看起来不错,其他两个将无法按预期工作,因为 Redirect 不适用于正则表达式作为 URL 路径(但 RedirectMatch 可以)。 如果您想知道为什么这些请求没有使用rewrite:trace6 记录,这也是mod_alias 而不是mod_rewrite 的功能。

    如果你想使用mod_rewrite,你可以使用RewriteRule,例如

    RewriteRule ^/download\.html$ /resource-center [R=301,L]
    

    【讨论】:

      猜你喜欢
      • 2016-10-02
      • 2014-11-10
      • 2017-07-28
      • 2011-08-23
      • 2013-09-27
      • 2016-08-08
      • 1970-01-01
      • 2020-02-06
      • 2021-05-02
      相关资源
      最近更新 更多