Welcome! Log In Create A New Profile

Advanced

Case insensitive option for 'rewrite' command

Posted by rbbot 
Case insensitive option for 'rewrite' command
March 09, 2010 10:26AM
I'd like to see an option for the rewrite command to make the regular expression use case insensitive matching.
Re: Case insensitive option for 'rewrite' command
December 02, 2010 06:05PM
If I was smarter (or had more time) I would write this into a separate module, but as it stands I modified the source for the rewrite command and added rewritei for case insensitive / non case sensitive rewrites. This does not solve general case sensitivity for everything ( I am going to be using ciopfs (case insensitive on purpose fs) fuse overlay file system on ubuntu for that), but this redirect thing was still a pain (where I had old, capitalized and uncapitalize links to asp pages). Here is what I did:

first off I installed nginx from ubuntu repositories (aptitude install nginx)
aptitude install libpcre3-dev
download and extract nginx source
download and extract need 3rd party modules (I added upstream-fair as the default ubuntu one had this as well)
to get the configure options I did:
nginx -V
and copied the line from there, changing the path on the last one to point to the folder I extracted the upstream-fair to
The I changed the source for nginx-0.8.53/src/http/modules/ngx_http_rewrite_module.c and added the following lines

Below:
static char *ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
I added:
static char *ngx_http_rewritei(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);

Below:
{ ngx_string("rewrite"),
NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|NGX_CONF_TAKE23,
ngx_http_rewrite,
NGX_HTTP_LOC_CONF_OFFSET,
0,
NULL },
I copied the above and changed "rewrite" to "rewritei" and ngx_http_rewrite to ngx_http_rewritei
{ ngx_string("rewritei"),
NGX_HTTP_SRV_CONF|NGX_HTTP_SIF_CONF|NGX_HTTP_LOC_CONF|NGX_HTTP_LIF_CONF
|NGX_CONF_TAKE23,
ngx_http_rewritei,
NGX_HTTP_LOC_CONF_OFFSET,
0,
NULL },

Further down I copied the entire function for ngx_http_rewrite (around line 300, about 137 lines long), pasted it below where it was (with some whitespace of course), and then changed the first line from:
static char *
ngx_http_rewrite(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
To:
static char *
ngx_http_rewritei(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{

Then in this new function I changed the following section:
rc.pattern = value[1];
rc.err.len = NGX_MAX_CONF_ERRSTR;
rc.err.data = errstr;

To read:
rc.pattern = value[1];
rc.options = NGX_REGEX_CASELESS;
rc.err.len = NGX_MAX_CONF_ERRSTR;
rc.err.data = errstr;

I compiled it and tested it and it works fine (with much surprise and excitement on my part. it having actually worked :)
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 76
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready