Welcome! Log In Create A New Profile

Advanced

Rewrite url with "|" character?

Posted by aforty 
Rewrite url with "|" character?
April 07, 2014 01:29PM
Hi,
Been searching and searching but I can't seem to figure this out.

How do I rewrite a URL containing the pipe (|) character? If I try to do it with just a plain pipe then it seems to treat it like a regex OR and match it anytime I hit a url with the text before the pipe, which is obviously not desired. I've also tried to escape the pipe in a traditional regex way, no dice. If I try with URL encoded (%7C) it doesn't match at all.

rewrite ^/some/path/with|some|parameters$ /some/other/path permanent; # => matches anytime the url starts with /some/path/with
rewrite ^/some/path/with\|some\|parameters$ /some/other/path permanent; # => matches anytime the url starts with /some/path/with
rewrite ^/some/path/with%7Csome%7Cparameters$ /some/other/path permanent; # => never matches

Seems like URLs are un-encoded before processing, so %7C will not work. But how do I properly escape the pipe to make this work?



Edited 1 time(s). Last edit at 04/07/2014 01:31PM by aforty.
Re: Rewrite url with "|" character?
April 07, 2014 01:41PM
You know how it goes... as soon as you ask the question and think about it some more, the solution comes to you and you feel foolish for asking.

Here's how I did it:

rewrite ^/some/path/with[\|]some[\|]parameters$ /some/other/path permanent; # => matches ONLY /some/path/with|some|parameters


Cheers!
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 116
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready