How to use optional parameters in Yii URL Manager? - regex

I have a problem with Yii urlManager.
I have a page that is a list of videos, so I add the following rule:
'videos'=>'video/index'
Now I want to add the page:
'videos_pag<Video_page:\d+>'=>'video/index'
Is there a way in order to put the two rules together?
I tried this:
'videos(_pag<Video_page:\d+>)?'=>'video/index',
but it does not work properly.

Use two lines, if first fails, second will work (if everything correct) :)
'videos_pag<Video_page:\d+>'=>'video/index',
'videos'=>'video/index',

Related

Cloud Armor | allow multiple request paths in one line

I would like to allow only some of the request paths within one line rule like this
'[service,register,state]'.contains(request.path) && '[AT,DE,CH]'.contains(origin.region_code)
Unfortunately I am not sure how to tackle this since this since the last path with origin.region_code works fine for multiple occurences but not the request.path
The old way with only one string works request.path.contains('service')
But I need to make a map or working list out of it like '[service,register,state]'.contains(request.path)
The google docu does not help much here
okay it seems that the anwser was rather easy and regex a`like
just use this
request.path.matches('service|register|state')

Google Analytics: View Filter by Request URI - does this work?

I think this should be pretty straight forward but if I have a url(s) with a request URIs such as:
/en/my-hometown/92-winston
/en/my-hometown/92-winston/backyard
and I want to set up a GA view which only includes this page and any subpages, then does the following Filter work in Analytics?
Will that basically filter against and URI which specifically contains 92-winston or do I need to wrap it in a fancy regex? I'm not that great with RegEx.
Thanks! Apologies in advance if this is ridiculously easy.
You may want to try this regex, if you know exactly that the URI will start with "/en/my-hometown/92-winston":
^\/en\/my\-hometown\/92\-winston.*
This captures URI strings that start exactly with "/en/my-hometown/92-winston" and also include anything that may come after that, for example
/en/my-hometown/92-winston
/en/my-hometown/92-winston/backyard
/en/my-hometown/92-winston/some_other_page
Just beware that if you have more than one "Include" filter in GA, then you need to make sure you aren't actually excluding more data, as multiple include filters are "and"ed. Always test your new filters in your test view as well.

adding parameter to wordpress url without query string

i want to have parameter in friendly urls way, have done it with query string but this is not what i want
below is my link
http://www.example.org/category-name/sub-category/post-name-goes-here
and want to have link in template like this
http://www.example.org/category-name/sub-category/post-name-goes-here/parameter
it should still load the same single page but with parameter so i can use condition in single page template
how i can ignore this using rewrite rule or any other method?
You will need to add a rewrite rule so it doesnt try and "solve" the url address using its standard function .
See my previous answers here:
Add "custom page" without page
WordPress Rewrite based on form hidden field
you can pretty much add anything to the url after that.

Ember.js routing with parameters

I just played with ember routing example. It looks quite interesting. Especially if you are going to build all your application on Ember framework.
But parameters in url follows after '#'. That means you can't copy and send a link to someone if client has to login with postback (if only to set a cookie with login parameters). Is there a better option - maybe use '?' instead of '#'?
You may also have a look at Ember.Router.
There are two good start points # https://gist.github.com/2679013 and https://gist.github.com/2728699
A lot of fixes have been made the last couple of days.
EDIT
A brand new guide is now available # https://emberjs-staging-new.herokuapp.com/guides/outlets#toc_the-router
Here is a full example courtesy of https://github.com/jbrown
http://jsfiddle.net/justinbrown/C7LrM/10/

Match all characters in group except for first and last occurrence

Say I request
parent/child/child/page-name
in my browser. I want to extract the parent, children as well as page name. Here are the regular expressions I am currently using. There should be no limit as to how many children there are in the url request. For the time being, the page name will always be at the end and never be omitted.
^([\w-]{1,}){1} -> Match parent (returns 'parent')
(/(?:(?!/).)*[a-z]){1,}/ -> Match children (returns /child/child/)
[\w-]{1,}(?!.*[\w-]{1,}) -> Match page name (returns 'page-name')
The more I play with this, the more I feel how clunky this solution is. This is for a small CMS I am developing in ASP Classic (:(). It is sort of like the MVC routing paths. But instead of calling controllers and functions based on the URL request. I would be travelling down the hierarchy and finding the appropriate page in the database. The database is using the nested set model and is linked by a unique page name for each child.
I have tried using the split function to split with a / delimiter however I found I was nested so many split statements together it became very unreadable.
All said, I need an efficient way to parse out the parent, children as well as page name from a string. Could someone please provide an alternative solution?
To be honest, I'm not even sure if a regular expression is the best solution to my problem.
Thank you.
You could try using:
^([\w-]+)(/.*/)([\w-]+)$
And then access the three matching groups created using Match.SubMatches. See here for more details.
EDIT
Actually, assuming that you know that [\w-] is all that is used in the names of the parts, you can use ^([\w-]+)(.*)([\w-]+)$ instead and it will handle the no-child case fine by itself as well.