What does REST API path "/nfsList/{name:.+}" mean? - api

name:.+ in the path /nfsList/{name:.+} refers to subnet address.
Is /nfsList/{name:.+} the same as /nfsList/{name}? If not, does {name:.+} have some string format checks for subnet address?

.+ means any charachter including the slash /. So {name:.+} will capture foo/bar in /nfsList/foo/bar.
Without .+, {name} will capture only foo in /nfsList/foo, /nfsList/foo/bar will not match this URL.

Related

Redirect to new URL having looked up new "ID" in RewriteMap which appears in two places in the target URL

This one may have been answered but I can't seem to find one that fits my specifics. So apologies if it sounds old.
My rewrite consists of using a rewrite map and a redirect to another domain.
For example:
An old site has moved and new id's have been generated along with file name changes
So this URL:
https://www.example.com/gallery/951/med_U951I1424251158.SEQ.0.jpg
would need to be redirected to
https://www.example2.com/gallery/5710/med_U5710I1424251158.SEQ.0.jpg
The new value 5710 comes from a rewrite map lookup where I pass 951
there are two changes needed and the 2nd change has two possible variations:
The first change is gallery/951 to gallery/5710
The 2nd change is the filename where the id can be delimited in either of 2 ways:
U951I - delimited between a U and an I
or
U951. - delimited between a U and a .
I started with something like this:
RewriteRule "^gallery/(\d+)/(\s+)$"
But that is as far as I can get.
You could do something like the following:
RewriteCond ${MapName:$1|XXX} (.+)
RewriteRule ^/?gallery/(\d+)/(.*U)\1([I.][^/]+)$ https://www.example2.com/gallery/%1/$2%1$3 [R=302,L]
I'm assuming the domain being redirected to resides on a different server, otherwise (if this is in .htaccess) you would need to check the requested hostname in an additional condition (RewriteCond directive).
Explanation:
The regex ^/?gallery/(\d+)/(.*U)\1([I.][^/]+)$ matches and captures the relevant parts of the source URL...
^/?gallery/ - Literal text (optional slash prefix if this is being used in a server context, as opposed to .htaccess)
(\d+) - Captures the "old" member ID (later available using the $1 backreference and used to lookup the "new" member ID from the RewriteMap)
/ - literal slash
(.*U) - Captures the first part of the filename before the "old" member ID. Later available in the $2 backreference.
\1 - An internal backreference matches the "old" member ID that occurred in the 2nd path segment - Not captured.
([I.][^/]+)$ - Captures the last part of the filename after the "old" member ID - Later available in the $3 backreference. The character classs [I.] matches either an I or a literal . (the dot does not need to be escaped when used inside a character class). And [^/]+ matches everything thereafter to the end of the filename (URL-path).
The RewriteCond directive serves to lookup the new member ID (using the old member ID saved in the $1 backreference) in the rewrite map defined earlier in the server config. The result is then captured, which is later available in the %1 backreference. I set a default XXX so it would be easy to spot any lookups that fail.
Using the RewriteCond directive means we only lookup the rewrite map once. (Results are probably cached anyway, but it saves repetition at the very least.)
/%1/$2%1$3 - The substitution string is then constructed from the backreferences captured earlier:
%1 is the new member ID (captured in the preceding CondPattern)
$2 is the part of the filename before the member ID (captured by the RewriteRule pattern against the URL-path).
$3 is the part of the filename after the member ID.
Note that backreferences of the form $n refer to captured groups in the RewriteRule pattern and backreferences of the form %n refer to captured groups in the last matched CondPattern (RewriteCond directive).

HTACCESS: Redirect to home page if invalid number in url

I am using APACHE server and I want to redirect the url to home page if third parameter is invalid number.
Code I have written is ::
RedirectMatch 302 ^/app/([a-zA-Z0-9_-]+)/([a-zA-Z_-]+)/?$ /
But its not working.
In short:
www.xyz/app/test/3434 :: should pass
www.xyz/app/test/best :: should fail
www.xyz/app/test/34kkk34 :: should fail
You want to redirect when the last part is not a number. Stated otherwise, redirect when there's a non digit somewhere. To get this, you must first match any character including digits.
^/app/[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]*[a-zA-Z_-][a-zA-Z0-9_-]*/?$
Since you don't use any parts of the request in the target URL, there's also no need to capture anything ().
If you don't care about the particular characters, you can simplify the regular expression and just use .* instead of [a-zA-Z0-9_-]*, e.g.
^/app/.+?/.*?[^0-9].*/?$
You can use this rule:
RedirectMatch 302 ^/app/[a-zA-Z0-9_-]+/[a-zA-Z_-]+/[0-9]+/?$ /

How to rewrite URLs in htaccess that end with recurring characters

I have changed web platforms and have old URLs that I cannot and do not want to match on the new platform where the old content is now living.
I have an array of old product URLs that all have '-p-' in the URL, followed by a string of numbers and ending in .html (osCommerce platform URLs).
I would like to know how to rewrite:
/x/[rest-of-url]-p-[random numbers].html
to
/x/[rest-of-url]
I would like the end result to look something like this:
http://www.shop.com/shop/versace-black-snakeskin-pony-hair-hobo-p-2214.html
redirects to:
http://www.shop.com/shop/versace-black-snakeskin-pony-hair-hobo
Does anyone know if this is doable in the htaccess file as a rewrite rule?
My managed hosting service providers BeepWeb answered my question.
RewriteRule ^/shop/(.*)-p-(.*).html$ http://www.shop.com/product/$1/ [R=302]
The first argument is the URI that you are matching. The (.) matches any characters. The second argument is the destination URL. The $1 corresponds to the first (.). $2 would be the second (.*), and so on... The [R=302] tells the rewrite to be a 302 redirect (use [R=301] for a 301 redirect).
Using the (.) is essentially like using a wildard. You can instead narrow this down by specifying which characters you want to match as opposed to all characters (instead of using (.) you could use ([abc]*) which would match only against a, b and c characters).
Also, be careful that you do not match other URLs unintentionally (i.e. you need to make sure that the pattern matches are unique to the URLs being rewritten).
If you need the source reference, see the following:
https://httpd.apache.org/docs/current/rewrite/intro.html
Thanks again to http://www.beepweb.com for their detailed response.
Hope it helps others.

mod_rewrite from specific IP ranges

If a user is trying to access www.example.com/local
I want to send him to www.example.com/home if he has from a certain IP address, and www.example.com/work if he is not in that IP range.
What would be the best way to do that using mod_rewrite?
RewriteCond %{REMOTE_ADDR} ^123\.\123\.123\.123$
Also in the above example, what is the purpose of the backslashes and the $ sign?
I thought a backslash was an escape character, but then I'm not sure why you would be escaping the 1 in the 2nd group of digits
Thanks
(more questions in one is usually frowned upon, as I have seen it)
escaping a 1 is just a 1, I think,
$ means the end of the string
and ^ is the start except inside [].
the backslashes are meant to say that we look for a real . and not just any character.
You can test your regexes on your ip address ranges using for example regexr.com

Regex rule to match % sign in url for apache mod rewrite

Hello my rewrite rule is failling sometimes because my urls have % signs in them.
For example this url:
http://www.chillisource.co.uk/product/Grocery/Dr.%20Burnoriums%20Psycho%20Juice/1/B005MSE5KG/Psycho_Juice_70%_Ghost_Pepper
This is my rewrite rule:
RewriteRule ^product/([a-zA-Z]+)/([\sa-zA-Z0-9\-\+\.]+)/([0-9]+)/([A-Z0-9]+)/([a-zA-Z0-9]+) /product?&cat=$1&q=$2&page=$3&prod=$4&prodName=$5
How can I modify the 5th rule ([a-zA-Z0-9]+) to not fail on when there is a % in the product name ?
Thanks in advance.
Perhaps, it's not %20, but space. That is, the URL passed to rewrite adter urldecoding. If not, then just add percent sign to the range. (if yes — space).
---- Forget this part, I misunderstood the question ----
From what I get from the mod_rewrite documentation (http://httpd.apache.org/docs/current/mod/mod_rewrite.html), you should not have to deal with hex encoded characters (I assume that from the following statement:
THE_REQUEST
The full HTTP request line sent by the browser to the server (e.g., "GET /index.html HTTP/1.1"). This does not include any additional headers sent by the browser. This value has not been unescaped (decoded), unlike most other variables below.
In fact, using mod_rewrite would be practically impossible since you'd have to deal with that EVERYWHERE, e.g., you can always write %41 instead of 'A'.
--- But the following still is true ---
But your rewrite rule can't work, at least not with the request URL you posted: The last part of the regex "([a-zA-Z0-9]+)" is FAR too strict. In this case, it fails for the following reasons:
It lacks a treatment of the percent sign, as in "70%"
You forgot to include the underscore "_"
Try adding at least these two characters ("[a-zA-Z0-9%_]+") and it should work.