Scripts like this are probably being run by PHP (or similar server-side scripting language).
Doing so is a case of, on an apache server, adding something similar to the following in the .htaccess file:
RewriteCond %{QUERY_STRING} (.*)
RewriteRule ^trafficout/user/(\d+)$ some-script.php?%1&user=$1 [L]
What this is doing is looking for any requests for the above file, then passing in the query string ((.*)
) and user id ((\d+)
) into a php script.
What are %1 and $1 doing?
In a htaccess file %1
and $1
represent variables retrieved from RewriteCond
itions and RewriteRule
s. Specifically, %n
represents any variables acquired from a %{QUERY_STRING}
condition and $n
repesents any variables acquired from rules. In both cases n
represents the variable id. In the example above, there is one query string variable and one rewrite rule variable so both are 1
.
For the script in your question, this will turn the second part of our rewrite rule into:
some-script.php?limit=10&user=300
How we get the variables from the query string etc is done via Regular Expressions, and is a WHOLE other topic that I am not going to go into right now.
The PHP script will then get the variables using $_GET
or similar, for example:
$user = $_GET['user']; //bad example - no validation etc.
[L]?
This is a flag used to tell the server to stop processing any more rewrite rules.
No file extension
It is possible to call for a file without a file extension, as long as the script sets the correct content-type header, then the browser will process the returned file. In PHP, this would be done like:
<?php
header('Content-type: application/javascript');
And is sent before any content.
Google Ads
The original .js script is just a .js script. What the script is doing is generating an ajax call back to the Google Servers replacing local variables with whatever variables you have defined.