ignoreUrlParams AEM Dispatcher - aem

We have a situation to cache the html page even thought there is query parameter in the URL. Example: domain.com/test/test1?a=b&c=d, in this URL test.html must be cached and this can be achieved by "ignoreUrlParams" to ignore the query strings. However, that is not working as expected and the test page is not being cached. Also, when the URL with query parameter(s) is accessed the result is a 404. When the test.html is accessed first and create a manual cache for test.html the URL with query parameter works perfectly fine. Any suggestions?
We are on dispatcher-apache2.2-4.2.3.so. Thank you.

You can add as below -
/ignoreUrlParams {
/0001 { /glob "*" /type "deny" }
/0002 { /glob "query" /url "domain.com/test/test1" /type "allow" }
}

Related

request serves from cache even if value of parameter changes in AEM if we use /ignoreUrlParams in dispatcher configuration?

AEM docs says
When a parameter is ignored for a page, the page is cached the first time that the page is requested. Subsequent requests for the page are served the cached page, regardless of the value of the parameter in the request.
/ignoreUrlParams
{
/0001 { /glob "*" /type "deny" }
/0002 { /glob "q" /type "allow" }
}
if I add above entry in dispatcher configuration
GET /mypage.html?q=5
GET /mypage.html?q=65
gives same response as per documentation? If yes what is the benefit of /ignoreUrlParams and which scenario it will be useful?
This is because the default configuration from the docs is misleading and is actually the other way round :/
If you want the CACHE feature to ignore some Query param then you set it to "allow". If you want the CACHE feature to pass a request with a specific query to CQ you put "deny"
So if you have a search functionality using the q parameter then you should do:
/ignoreUrlParams
{
/0001 { /glob "*" /type "allow" }
/0002 { /glob "q" /type "deny" }
}

How do i rewrite all URL's ending in ?p=1 to the URL without that query in nginx

I have a website with pagination, which chooses the page to display using the 'p' query.
My issue is that
www.example.com/category.html and
www.example.com/category.html?p=1
Are the same content, and are showing as duplicates for SEO purposes, how do i redirect all ?p=1 queries in nginx to their query free counterpart.
Thanks
The value of the p argument is contained in the $arg_p variable. The if statement can be used to test the value of a variable. The actions available in an if block are limited (see this document for details), but a simple return statement is allowed.
So the simplest solution would be to obliterate the query string from any URI which contains p=1, like this:
server {
...
if ($arg_p = 1) {
return 301 $uri;
}
location / { ... }
}
Note that $uri is the normalised request URI, and is already missing the query string.

Spray.io Path Directives serve index.html

I want to set up a Spray route to serve web content out of a directory.
For example, the below URLs should resolve to the same file.
http://mywebsite.com/path/to/thing
http://mywebsite.com/path/to/thing/
http://mywebsite.com/path/to/thing/index.html
Should serve the index.html file from the filesystem at ./web/path/to/thing/index.html
The following route works if "index.html" is explicitly specified but not otherwise.
pathPrefix("") {
getFromDirectory("./web/")
}
How do i represent this in Spray routing?
Assuming you have already matched up to "thing" with pathPrefix, I think you want pathEndOrSingleSlash, described here. I didn't think that Spray-routing would match an implicit "index.html", but in any case you can compose directives easily if you need to:
(pathEndOrSingleSlash | path("index.html")) { ... }
UPDATE:
OK, from your comment I am thinking that you just want to take whatever path was specified and serve up the file from that directory. Something like this (untested)?
path(Segment) { rawPath =>
getFromFile("web/" + if (rawPath endsWith "/") rawPath + "index.html" else rawPath)
}

Nginx redirect URL with specific query parameter

Nginx, I am trying to permanently redirect the URLs with a device GET parameter (http://www.example.org/page?device=desktop) to the relative URL without this parameter (http://www.example.org/page).
I did this, but it doesn't work.
location {
rewrite ^(.*)\?device=desktop $1 permanent;
}
Each query parameter is exposed as a variable prefixed with $arg_ in the configuration file. For example, device would become $arg_device. Using this you can make the comparison check within your location block, for example:
location / {
if ($arg_device = desktop) {
return 301 $uri;
}
}

how to do nginx rewrites from a url with get parameters

This is my first ever StackOverflow question so please bear with me.
Nginx serves many different sites for us and we have a lot of redirects from migrating clients from different vendors and such. We have set up an /includes directory that houses redirect files for each domain that we migrate over. Occasionally, we will need to write redirects from a url that contains get parameters:
http://example.com/content/default.aspx?NewsId=28
To do this, we have been doing this in an nginx /includes file called example.com-redirects
location ^~ /content/default.aspx {
if ($args ~ "NewsId=28") { rewrite ^ http://example.com/news? permanent; break; }
# add more statements like the one above
}
That has worked just fine for us thus far. Unfortunately, we need to do the same thing but for a different domain that could have the same get parameters. And of course nginx doesn't allow for duplicate locations.
location ^~ /content/default.aspx {
if ($args ~ "NewsId=28") { rewrite ^ http://differentexample.org/news? permanent; break; }
}
I've tried a couple of different solutions all giving me syntax errors. No one at my company is an nginx expert anymore so I could really use some help solving this. I have added an if ($host ~ "example.com") within the location block and that gave me an error. And I've tried adding the location block within the if ($host ~ "example.com") block. Both times nginx told me that I can't put that there.
I usually find my answer in the vast knowledge base that is the internet but seem to be striking out on a solution for this and we're running out of time before we launch this client.
Instead of using if, use a variable. In the virtual host config you set this variable. In the include with the location you use it:
server {
...
set $redirect_host "example.org";
include /includes/news28.conf;
...
}
# include part
location /foo {
if ($args ~ "NewsId=28") { rewrite $scheme://$redirect_host/news? permanent; }
}
Of course you need to set that variable also in the server config of the host already using this include. Hope this helps.