HTTP_REFERER语法

时间:2017-05-22 07:16:35

标签: php apache .htaccess http mod-rewrite

我正在使用此代码

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^https://(subdomain\.)?domain\.com/ [NC]
RewriteCond %{REQUEST_URI} !hotlink\.(gif|png|jpg|jpeg|doc|xls|pdf|html|htm|xlsx|docx|mp4|mov|mp3) [NC]
RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC]
RewriteRule .*\.(gif|png|jpg|jpeg|doc|xls|pdf|html|htm|xlsx|docx|mp4|mov|mp3)$ https://subdomain.domain.com/ [NC]

关于https://(subdomain\.)?domain\.com/是正确的引用语法

  

http://subdomain.domain.com/
  http://www.subdomain.domain.com/
  https://subdomain.domain.com/
  https://www.subdomain.domain.com/

2 个答案:

答案 0 :(得分:0)

这应该做:

^https?://(www\.)?subdomain\.domain\.com/
  

说明:

     

^在字符串

的开头断言位置      

http匹配字符http字面

     

s - 字符匹配

     

? - 量词,匹配0到1次之间的字符“s”

     

:// - 匹配字符://字面意思

     

www - 匹配字符www字面

     

\. - 匹配字符“。”字面意思

     

? - 量词,匹配组“www。”在零到一次之间

     

subdomain - 字面匹配字符“subdomain”

     

\. - 匹配字符“。”字面意思

     

domain - 字面匹配字符“domain”

     

\. - 匹配字符“。”字面意思

     

com/ - 字面匹配字符“com /”

https://regex101.com/r/TcOZuw/1

答案 1 :(得分:0)

你能否确认

RewriteEngine On RewriteCond %{HTTP_REFERER} !^https?://(www\.)?subdomain\.domain\.com/ [NC] RewriteCond %{REQUEST_URI} !hotlink\.(gif|png|jpg|jpeg|doc|xls|pdf|html|htm|xlsx|docx|mp4|mov|mp3) [NC] RewriteCond %{HTTP_COOKIE} !^.*wordpress_logged_in.*$ [NC] RewriteRule .*\.(gif|png|jpg|jpeg|doc|xls|pdf|html|htm|xlsx|docx|mp4|mov|mp3)$ https://subdomain.domain.com/ [NC]

参考 http://subdomain.domain.com/ http://www.subdomain.domain.com/ https://subdomain.domain.com/ https://www.subdomain.domain.com/