Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8851141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:04:40+00:00 2026-06-14T13:04:40+00:00

I have the following snippet: RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^https?://%{SERVER_NAME}/ RewriteRule \.(js|css|png|jpg) –

  • 0

I have the following snippet:

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^https?://%{SERVER_NAME}/
RewriteRule \.(js|css|png|jpg) - [R=404,L]

Simple and should work right? It seems to 404 the listed filetypes if I have referrers enabled on browser. Disabling referrers it then allows the files to be served. I have checked the value of %{SERVER_NAME} and it is http://www.mydomain.com I’ve tested this in multiple browsers and under HTTP and HTTPS, all have the same result. I used the below rewrite to check %{SERVER_NAME}’s value:

RewriteRule servername value_is_%{SERVER_NAME} [R=301,L]

The URL I get redirected to is then https://www.mydomain.com/value_is_www.mydomain.com

That being said the snippet should allow a referrer with that value or an empty one. But why is it being triggered? It’s been driving me nuts for the past 2 hours, but it’s 5am so I could be just crazy =o\ Thank you in advance, and I’m off to bed!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T13:04:41+00:00Added an answer on June 14, 2026 at 1:04 pm

    Problem is, you cannot use variables in conditional patterns (well, at least not until Apache 2.4) as the patterns are being precompiled during server startup.

    For your particular problem, though, there’s a simple workaround that you may use to mimic the condition:

    RewriteCond %{HTTP_REFERER} !^$
    RewriteCond %{SERVER_NAME}%{HTTP_REFERER} !^(.*)https?://\1/
    RewriteRule \.(js|css|png|jpg) - [R=404,L]
    

    Yep, that’s all. You cannot use variables but sure can use back-references.

    Oh … and btw. Apache 2.4 does ship with expressions that may be used instead of the conditional patterns:

     RewriteCond expr "! %{HTTP_REFERER} -strmatch '*://%{HTTP_HOST}/*'"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following snippet that overwrites certain CSS properties:- var styleSheet = document.styleSheets[2];
I have following code snippet that i use to compile class at the run
I have following code snippet: class ABC{ public: int a; void print(){cout<<hello<<endl;} }; int
I have the following snippet of code: import csv def has_header(first_lines): sniffer = csv.Sniffer()
We have the following snippet. OSStatus createErr = PasteboardCreate(kPasteboardClipboard, &m_pboard); if (createErr != noErr)
I have the following snippet from my code: switch ($extention) { case gif: $src
I have the following snippet of java code: File directoryToMoveTo = new File(file.getParent()+_TEMP); boolean
I have the following snippet in my pom.xml (Full pom attached below which can
I have the following snippet of code (I'm using jQuery 1.4.2): $.post('/Ads/GetAdStatsRow/', { 'ad_id':
I have the following (snippet) of a kernel. __global__ void plain(int* geneVec, float* probs,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.