【问题标题】:.htaccess mod_rewrite.c using HTTP_REFERER.htaccess mod_rewrite.c 使用 HTTP_REFERER
【发布时间】:2017-07-06 17:53:20
【问题描述】:

当在 URL 栏中输入 http://www.example.org/aa/doesntexist.php 时,我试图让 .htaccess 获取页面 http://www.example.org/aa/exists.php.htaccess 文件显然可以正常工作,因为 DirectoryIndex 行正在产生所需的结果,URL 栏中的 http://www.example.php 获取页面 http://www.example.php/aa/default.php

我尝试根据我的情况调整对how to redirect using HTTP_REFERER on htaccess 的回复,但没有成功。

以下是我的.htaccess 文件的全文。

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_REFERER} ^(.*)www\.example\.org/aa/doesntexist\.php [NC]
    RewriteRule ^(.*)(www\.example\.org/aa/)doesntexist\.php(.*)$ $1$2exists.php$3 [NC,L]
    DirectoryIndex aa/default.php
</IfModule>

http://www.example.org/aa/doesntexist.php 的请求会产生以下错误:

找不到

在此服务器上找不到请求的 URL /aa/doesntexist.php。

此外,在尝试使用 ErrorDocument 处理请求时遇到 404 Not Found 错误。

【问题讨论】:

    标签: apache .htaccess mod-rewrite http-referer


    【解决方案1】:

    尝试在启动引擎之前添加Options +FollowSymlinksAllow Override All 作为第一条命令。

    我看不出你的条件或规则有什么问题。我最近有一个非常相似的问题,可以通过这种方式解决。 如果这不是问题,你可以看看http://forum.modrewrite.de/topic82.html 不幸的是,它是德语的,但也许仍然有帮助 - 至少借助谷歌翻译(肯定不完美,但足够好)。

    顺便说一句:如果有理由检查引荐来源网址,而不仅仅是请求的 URI,请保留它。否则,仅此规则就可以满足您的要求。如果条件的内容与规则的模式匹配,则不需要条件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多