Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify case-insensitive rule with rewrite middleware?

I have the following:

var options = new RewriteOptions()
    .AddRedirect("home/(.*)", "/$1")
    .AddRedirect("Home/(.*)", "/$1")
    .AddRedirect("downloadics/(.*)", "ics/$1")
    .AddRedirect("DownloadICS/(.*)", "ics/$1");

I would like to have it so that the I can just have one entry for home and one entry for download ics and have it not be case sensitive.

I tried passing (?) to the front of the regex but it seems to blow up on that.

like image 692
Zoinky Avatar asked Jan 28 '23 21:01

Zoinky


1 Answers

You can make these regular expressions case-insensitive by adding a (?i) at the very beginning. This adds the i flag which generally means “case insensitive”:

var options = new RewriteOptions()
    .AddRedirect("(?i)home/(.*)", "/$1")
    .AddRedirect("(?i)downloadics/(.*)", "ics/$1");
like image 141
poke Avatar answered Jan 31 '23 12:01

poke