Forum Moderators: phranque
1) Via the x-up-calling-line-id= value at the end of the header
2) Via the x-msisdn= value at the end of the header
3) Via a value msisdn included in the query (e.g. /page.jsp?msisdn=
Is it possible to create a mod_rewrite rule that will standardise this value to for example msisdn= in the header and if so, could you provide some guidance on how to do this.
I came across someone who had a similar issue and they solved it as follows;
# Request headers
<IfModule !mod_headers.c>
LoadModule headers_module modules/mod_headers.so
</IfModule>
# Copy the MSISDN to an internal variable
RewriteEngine On
RewriteCond %{HTTP:MSISDN} .*\s(.*)
RewriteRule .* - [E=MSISDN:%1]
# Set the XX-MSISDN header
RequestHeader set XX-MSISDN %{MSISDN}e
However when I tried this, it broke the query completely.
The code above uses two modules when one would do, and the naming of the variable is inconsistent -- x-msisdn, MSISDN, and xx-MSISDN are all mentioned.
Also, what is the specific, detailed meaning of "broke the query completely"?
With server config code, everything is in the details...
Jim
GET /m/page.jsp;jsessionid=7CE68B4099B3AE8BF3D4BF1E767FDA52.worker3 HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://www.example.com
Cookie: JSESSIONID=7CE68B4099B3AE8BF3D4BF1E767FDA52.worker3
x-msisdn: 27821111111
GET /m/page.jsp;jsessionid=7CE68B4099B3AE8BF3D4BF1E767FDA52.worker3 HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://www.example.com
Cookie: JSESSIONID=7CE68B4099B3AE8BF3D4BF1E767FDA52.worker3
x-up-calling-line-id: 27831111111
GET /m/page.jsp?msisdn=27841111111;jsessionid=7CE68B4099B3AE8BF3D4BF1E767FDA52.worker3 HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://www.example.com
Cookie: JSESSIONID=7CE68B4099B3AE8BF3D4BF1E767FDA52.worker3
Note that in the last example the network appends the msisdn field to the actual query.
I'm not sure how it actually broke the query but I could not aaccess our site.
This code implements a priority scheme such that the variables are accepted in this priority: if present in the HTTP request, x-msisdn overrides x-up-calling-line-id, which (if present) overrides the query string "msisdn=xyz" name/value pair. If none are present, then the MSISDN variable will not be set, and the value of the XX-MSISDN request header will be the single character "e".
This code is intended only for use in a server config file (e.g. httpd.conf or conf.d) and not for use in .htaccess files.
# Enable mod_rewrite
Options +FollowSymLinks
RewriteEngine on
#
# Get X-MSISDN, X-UP-CALLING-LINE-ID, or msisdn query string value to server variable MSISDN
RewriteCond %{HTTP:X-MSISDN} ^((.+))$ [OR]
RewriteCond %{HTTP:X-MSISDN}>%{HTTP:X-UP-CALLING-LINE-ID} ^>((.+))$ [OR]
RewriteCond %{HTTP:X-MSISDN}>%{HTTP:X-UP-CALLING-LINE-ID}>%{QUERY_STRING} ^>>([^&;]+[&;])*msisdn=([^&;]+) [NC]
RewriteRule ^/m/page\.jsp$ - [E=MSISDN:%2]
#
# Load mod_headers module if not already compiled-in
<IfModule !mod_headers.c>
LoadModule headers_module modules/mod_headers.so
</IfModule>
#
# Set request header XX-MSISDN to value of MSISDN variable, plus "e"
RequestHeader set XX-MSISDN %{MSISDN}e
As shown, the rule is only applied to requests for the /m/page.jsp URL-path.
If this does not work, then I'm afraid you're going to have to find someone at your end who knows how this whole thing is supposed to work -- Exactly how the header info is supposed to be prioritized and passed, and what/where and when that info is supposed to be passed to. I'll freely admit that I'm just guessing here.
For example, is the MSISDN variable used anywhere but in this code? How about the msisdn query string name/value pair? And finally, why is it necessary to have and use three different methods of passing this data? -- It all seems a bit over-complicated to me.
Jim
Thank you for your assistance with this, it's much appreciated. I think I just need to clarify one or two things.
The code I posted which showed a Rewrite Rule using XX-MSISDN was not my own but something I came across on the internet, hence their requirement was slightly different from mine.
The reason there are three different methods of passing the data has to do with the three cellular networks who forward requests from their customers via a wap gateway, each of which implements the msisdn value differently.
I tried implementing your recommendation above, with one change. I modified
RewriteRule ^/m/page\.jsp$ - [E=MSISDN:%2]
to
RewriteRule ^/$ - [E=MSISDN:%2]
The reason for the change is that I need the rule applied for all URL requests and not just for that page or directory.
Using the Live HTTP headers plugin on Firefox, the change did not seem to make any difference. I also tried to enable logging of re-writes by adding the following in my Virtual Host entry below the code you gave me.
RewriteLog "/usr/local/apache/logs/rewrite.log"
RewriteLogLevel 3
No entries were created in the file and so I moved the two lines above to my httpd.conf and tried again with no result.
Any idea what I could be doing wrong?
See the short regular expressions tutorial in our Forum Charter for more info.
You're going to need to find out how your scripts expect the msisdn value to be passed to them, and tweak the code to suit.
Jim