$ _SERVER [' HTTP_REFERER']和RewriteCond%{HTTP_REFERER}显示不同的数据

时间:2016-01-05 07:46:56

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

为什么RewriteCond不起作用?

htaccess的:

RewriteEngine on
RewriteBase /

RewriteCond %{HTTP_HOST} !^example\.com
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]

RewriteRule ^page([0-9]+).html$ index.php?page=$1

RewriteRule ^p([0-9]+)-([a-zA-Z0-9_]+).html$ index.php?id_post=$1&title_post=$2
RewriteRule ^([a-zA-Z0-9_\-]+)/page([0-9]+).html$ index.php?mpoint=$1&page=$2 [L]
RewriteRule ^([a-zA-Z0-9_\-]+).html$ index.php?mpoint=$1
RewriteRule ^.*.html$ index.php?mpoint=$1


RewriteCond %{HTTP_REFERER} ^www.example111.com$ [NC,OR]
RewriteCond %{HTTP_REFERER} ^example222.ml$ 
RewriteRule .* – [F]

index.php

echo $_SERVER['HTTP_REFERER'];

结果:http://www.example111.com/xxxx/yyy.html

1 个答案:

答案 0 :(得分:1)

这是因为$模式中的RewriteCond。它将比赛锚定到最后。因此

^example222.ml$

将匹配确切的字符串example222.ml,这不是这里的情况。尝试:

RewriteCond %{HTTP_REFERER} ^(www\.)?example111\.com [NC]
RewriteRule ^ – [F]