【问题标题】:How can i write if condition statement in htaccess - Apache 2.2.15我如何在 htaccess 中编写 if 条件语句 - Apache 2.2.15
【发布时间】:2016-08-17 04:42:28
【问题描述】:

我在 Wordpress 之外使用了几个文件夹,如果文件不存在,我想显示一个自定义 404 文件(不是 404 标准 Wordpress 页面)。在这些文件夹中,我有一个 .htaccess,只有 2 行“RewriteOptions Inherit”和“ErrorDocument 404 /err/404.php”。它工作正常,但问题是有时某些广告横幅未在其脚本中使用其域,并且我的日志中有错误。

[the_date] [error] [client IP] File does not exist: /home/admin/web/my_domain.com/public_html/folder_outside_wordpress/undefined, referer: http://my_domain.com/folder_outside_wordpress/my_file.php

基本上,如果在他们的脚本中是/folder/file.php 而不是http://ads-domain.com/folder/file.php,我的日志文件中就会出现错误,这是正确的,因为我使用的是RewriteOptions Inherit。 所以,我的意思是只有在请求的文件丢失时才使用“RewriteOptions Inherit”行,就像这样。

if (status == 404)
{
RewriteOptions Inherit
ErrorDocument 404 /err/404.php
}

Apache 2.2.15 版

【问题讨论】:

    标签: apache .htaccess


    【解决方案1】:

    我发现另一个option 没有使用RewriteOptions Inherit

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^.*$ /err/404.php [L]
    

    【讨论】:

      猜你喜欢
      • 2011-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-24
      • 1970-01-01
      • 2016-06-28
      • 1970-01-01
      • 2022-11-29
      相关资源
      最近更新 更多