2f 28 5ba z 0 9 5d 2a 29 php

Solutions on MaxInterview for 2f 28 5ba z 0 9 5d 2a 29 php by the best coders in the world

showing results for - " 2f 28 5ba z 0 9 5d 2a 29 php"
Miranda
17 Jul 2016
1RedirectMatch 301 ^/news/([0-9]+)-(.*) /blog
2RedirectMatch 301 ^/news/([a-z]+)-(.*)/$ /blog/$1
3
Anae
20 May 2020
1RedirectMatch 301 ^/news/([0-9]+)-(.*) /blog
2RedirectMatch 301 ^/news/([a-z]+)-(.*)/$ /blog/$1
3
4
5These are regular expressions ("regex" for short). Specifically, Apache uses PCRE (Perl Compatible Regular Expression) syntax (the same as PHP, similar to JavaScript, etc.).
6
7RedirectMatch 301 ^/news/([0-9]+)-(.*) /blog
8RedirectMatch 301 ^/news/([a-z]+)-(.*)/$ /blog/$1
9The RedirectMatch directive tries to match the regex (2nd argument) with the requested URL-path. If it matches then a redirect response is returned, to redirect the browser to the target URL (3rd argument).
10
11The $1 backreference in the target URL of the second example copies text that has matched in the source URL-path. eg. Given a request for /news/abc-123/, the abc part is "copied" in order to redirect to /blog/abc (see later).
12
13([0-9]+)-(.*)
14This basically matches 1 or more digits followed by a hyphen (followed by anything). Specifically:
15
16[0-9] - This "character class" (denoted by [..]) matches a single character in the range 0-9, ie. a digit.
17+ is a "quantifier" and matches 1 or more of the preceding character/group. So it matches 1 or more digits.
18- this hyphen is matched literally (it carries no special meaning when used outside of a character class).
19.* matches any number of characters (except newline). Specifically . matches any character (except newline) and * is a quantifier that matches 0 or more of the preceding character/group. (Contrast with + which matches 1 or more.)
20The parentheses (..) that surround parts of the regex make "capturing groups", which can be used later using backreferences. However, these are not being used here.
21The above can be simplified (since none of the backreferences are used). We just need to match 1 or more digits, followed by a hyphen:
22
23\d+-
24\d is a shorthand character class that matches digits. ie. the same as [0-9].
25
26([a-z]+)-(.*)/$
27Very similar to the above, except it matches 1 or more lowercase letters (a-z), followed by a hyphen, followed by anything, before ending with a literal slash.
28
29$ is an anchor signifying the end of the the string, ie. the end of the URL-path when used here. Conversely, ^ matches the start of the string, ie. the start of the URL-path (as opposed to some point in between).
30Contrary to the first regex, the first backreference ($1) is used in this example, which captures whatever matches ([a-z]+). So, for example, /news/abc-123/ is redirected to /blog/abc.
31
32This can't be simplified as much as the first regex, because of the capturing backreference and trailing slash. But the second group of parentheses could be removed:
33
34([a-z]+)-.*/$