Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Issues with percentage signs in URL redirection

Last post 01-10-2009, 4:46 AM by prometheuzz. 4 replies.
Sort Posts: Previous Next
  •  01-09-2009, 10:35 PM 49993

    Issues with percentage signs in URL redirection

    Hi,

    Although technically reasonably competent - I am a newbie to the world of RegEx.

    A have a website/blog and have been tidying up my URL's and have been having trouble in creating a regex to redirect URL's such as this one:

    "/2007/04/06/rantings-%e2%80%9cmore-wailing%e2%80%9d-written-3407/"

    to:

    "/2007/04/06/rantings-more-wailing/"

    It's the "%e2%80%9c" in the URL that's causing me issues.

     

    Any help or advice would be greatly appreciated.

    Cheers,

     

    Robert
     

     

  •  01-09-2009, 11:31 PM 49994 in reply to 49993

    Re: Issues with percentage signs in URL redirection

    Hi,

    easy possible to filter out with preg_replace():

     $righturl = preg_replace('/%\w{2}/', '', $oldurl);

  •  01-10-2009, 12:40 AM 49995 in reply to 49994

    Re: Issues with percentage signs in URL redirection

    Hi,

     

    Thanks for responding.

    The only issue is I'm not doing the redirection in Apache. Rather doing it in Wordpress using a Redirection plugin that allows me to enter redirections on URL's in regex.

    So I basically need to get a match on "%e2%80%9c" and "%e2%80%9d".

    I tried the following based on your example (which did not work):

    Source URL: /2007/04/06/rantings-%e2%80%9cmore-wailing%e2%80%9d-written-3407/  (external request)

    Regex: /2007/04/06/rantings-(/%\w)more-wailing(/%\w)-written-3407/  (redirection plugin field)

    Target URL: /2007/04/06/rantings-more-wailing/  (redirection plugin field)

     

    Any further input or ideas you might have would be greatly appreciated.

    Regards,

  •  01-10-2009, 1:24 AM 49996 in reply to 49994

    Re: Issues with percentage signs in URL redirection

    Hi,

     

    Found a way...

    The unusual string of characters eg: "%e2%80%93" can simply be matched with a "(.+)" (no quotes) 

    I'm sure there's a better way but I'm new to regex and I'm happy that I'm now able to redirect the URL's that I want to. 

    Regards,

     R
     

  •  01-10-2009, 4:46 AM 50001 in reply to 49993

    Re: Issues with percentage signs in URL redirection

    Many programming languages have utility methods to "decode" (or "encode") strings into url's (and back). In PHP your could use the urldecode($url_str) method for example.
View as RSS news feed in XML