Forum Moderators: phranque
this template file always displays in log files as having been requested by the domain ip instead of by the visitor ip
If I block requests
[edited by: JS_Harris at 8:19 am (utc) on Feb 11, 2016]
My site has an area that, via php, calls a template file
// By specifying an absolute URL, PHP makes an external HTTP for the resource
include('http://example.com/templates/mytemplate.html');
// Include the file from the local filesystem (normal)
include($_SERVER['DOCUMENT_ROOT'].'/templates/mytemplate.html');
dirname(__FILE__) . "/etc...
<?php include('hello.php');?> RewriteCond %{HTTP_USER_AGENT} ^-?$
RewriteRule .* - [F] RewriteCond %{HTTP_USER_AGENT} ^-?$
RewriteRule .* - [NS,F] Options -Indexes
Options +FollowSymlinks
Options -MultiViews
RewriteEngine On
RewriteBase /
BrowserMatch ^-?$ keep_out
followed by a mod_auththingummy directive. <?php include('hello.php');?>
<?php include('./hello.php');?>
<?php
function helloworld() {
return 'Hello World';
}
<?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors','1');
include('helloworld.php');
echo helloworld();
shouldn't the referrer have been the same for ALL of those requests from that one hit?
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_USER_AGENT} ^-?$
RewriteRule .* - [F] RewriteCond %{HTTP_USER_AGENT} ^-?$
RewriteCond %{REQUEST_URI} !=/full/path/of/problempage\.php
RewriteRule .? - [F]The above worked to allow blocking of blank user agents/referrers. !^/problempage.php, !^/problempage\.php or !^problempage\.php did not work, full path with '=' required?! The server still insists on calling that one file so every log file entry for a valid url that requires it be included results in a second log file entry for that one file by the domain ip. I did not add [NC] to the request URI since the server will never request mixed or upper case but people might, or is that incorrect? I did not add [NC] to the request URI since the server will never request mixed or upper case but people might, or is that incorrect?
full path with '=' required?!
That's why only one file is displayed in the code snippet above, even though two are being called. The problem seems to cascade.
I still don't get why the internal request is even showing up in logs at all, though. Mine don't.
RewriteCond %{REQUEST_URI} !=/full/path/of/problempage\.php
Requiring the full path does imply that this rule is executing at some later time, after paths have been worked out.
If I'm getting it right, the server only counts the first include as a loggable request, and then everything else happens quietly behind the scenes the way it's supposed to?
Incidentally, if you are using the "=" operator, there is no need to escape the dot (although I guess it doesn't matter either?).Correct BUT it does matter, the dot could not be escaped. I double checked the working code and the dot is not escaped because doing so causes it to fail and throw a 403 error for that request. ie: the internal request is not ignored, the server takes the backslash as a literal part of the URI. I put the wrong version up above, remove the dot escape if you try it.
Correct BUT it does matter
Although the REQUEST_URI variable would never "normally" contain the filesystem path? (Or could it?)
The addon domain is reachable directly OR by visiting addon.primarydomain.com
- The host creates a catchall redirect from subdomains to a folder of the subdomain at the server level(not in htaccess, can't be overridden)
That last part is the problem, anything.primarydomain.com becomes primarydomain.com/anything and there is no way to stop this behavior, it's how they handle addon domains
Header always set X-Content-Type-Options "nosniff" Visiting the addon domain and checking headers I see X-Content-Type-Options nosniff,nosniff so it's combining commands from both htaccess files.
reaching the content on siteb.sitea.com uses the htaccess file of sitea to access siteb
...but I figured it out(99% sure anyway).
That catchall redirect IS resulting in the problem I described in the OP since my site's htaccess forbids it from working.
- The addon domain is reachable directly OR by visiting addon.primarydomain.com
- The host creates a catchall redirect from subdomains to a folder of the subdomain at the server level
That last part is the problem, anything.primarydomain.com becomes primarydomain.com/anything and there is no way to stop this behavior
Unfortunately the host redirect causes 3 different versions of the content found on any addon domain.
siteb.sitea.com
sitea.com/siteb
siteb.com
a webmaster may think siteb.com is protected thanks to the htaccess file on siteb.com but since reaching the content on siteb.sitea.com uses the htaccess file of sitea to access siteb some of the rules may or may not work at all.
But doesn't siteb.sitea.com redirect to sitea.com/siteb? So, only really 2 different versions are found?
To test: On the primary domain level I included an htaccess file telling a browser to return a nosniff header. On the addon domain level, I placed a 2nd htaccess file in the root folder of that addon domain which said to return a noimageindex header.
<snip>
Result: When visiting the primary domain there is only a nosniff header result but when visiting the addon domain you get nosniff + noimageindex headers with this host, 2 different commands from 2 different files placed at the root level of 2 individual sites(1 primary, 1 addon) = both show for the addon domain.
ie: primary domain = only a nosniff entry and addon domain = only a noimageindex headerDo you mean that this is what you expected to happen? The expectation was incorrect, though :(