Intelligencia URLRewriter HTTP to HTTPS - redirect

I am trying to get URLRewriter to force redirect a HTTP requests to a HTTPS. The vendors documentation doesn't seem to cover it.
I know the following parameters throws an error but serve to illustrate what I am trying to accomplish:
<rewriter>
<if url="http://www.domain.com/test*">
<rewrite url="http://www.domain.com/test*" to="https://www.domain.com/test*" />
</if>
</rewriter>

It would be useful to know exactly what error is thrown to make sure I am heading down the right path here but I think you are using the * character when you mean to use the . character (possibly .+ if you are intending any non secure URL to be redirected to the secure version)

It seems like what the original poster wanted to do was something like:
<rewriter>
<if url="http://.*">
<rewrite url="http://([^/]*)(.*)" to="https://$1$2" />
</if>
</rewriter>
However, that doesn't seem to work at all - I'm not really sure what it's doing under the hood to understand why. The regexes seem to be sound. I found this site really helpful for figuring some of this out: http://regexhero.net/tester/
I finally found the magic incantation to make it work, from:
https://webmasters.stackexchange.com/a/31318
<rewriter>
<if header="HTTPS" match="^OFF$">
<redirect url="(.*)" to="https://yourdomain.com$1"/>
</if>
</rewriter>

Related

Web.config - Rewrite rule for redirecting with multiple queries in one URI

I have this issue where I want to redirect domain.com/profile.php?user=username&page=1
I have a rule for just redirecting to the user query but when I use the following rule in the web.config for both queries I get server error 500. Is there any wrongs in my rule?
<rule name="rule 2Q">
<match url="^profile/([^/]*)/([^/]*)" />
<action type="Rewrite" url="/profile.php?user={R:1}&page={R:2}" />
</rule>
Edit: Forgot to mention that the link I want to enter in the web browser is domain.com/profile/[username]/[pageid]
but the webserver should process this as domain.com/profile.php?user=username&page=1
I'm not sure which regex parser your web server uses, however, I would suggest something (PCRE compatible) might be more appropriate, /^profile\/(.+)\/(.+)/. If the url contains more variants than you describe then maybe a less greedy regex expression might be in order.

Discovering the version of a SPARQL endpoint

Given a SPARQL endpoint (which can be either SPARQL 1.0 or 1.1), say for example http://pt.dbpedia.org/sparql, how do I find which version of SPARQL it supports?
[One option is to try out a 1.1 feature such as aggregate functions and see it works but I guess there should be a better way to do this].
The SPARQL 1.1 Service Description specification says
SPARQL services made available via the SPARQL Protocol should return a
service description document at the service endpoint when dereferenced
using the HTTP GET operation without any query parameter strings
provided. This service description must be made available in an RDF
serialization, may be embedded in (X)HTML by way of RDFa [RDFA], and
should use content negotiation [CONNEG] if available in other RDF
representations
and further,
3.2.10 sd:supportedLanguage
Relates an instance of sd:Service to a SPARQL language (e.g. Query and Update) that it implements.
subPropertyOf: sd:feature domain: sd:Service range: sd:Language
3.3.3 sd:Language
An instance of sd:Language represents one of the SPARQL languages, including specific configurations providing
particular features or extensions. This document defines three
instances of sd:Language: sd:SPARQL10Query, sd:SPARQL11Query, and
sd:SPARQL11Update. type: rdfs:Class subClassOf: sd:Feature
But when I dereference most of the SPARQL endpoints, they just sends me an HTML SPARQL query editor.
UPDATE:
HTML editor issue was because I didn't use proper content negotiation on the endpoint. But now the question is there a good way to differentiate between a SPARQL 1.0 endpoint and a SPARQL 1.1 endpoint that doesn't provide a service description?
There are some work done on discovering and monitoring SPARQL endpoints such as SPARQL Web-Querying Infrastructure: Ready for Action?, Discoverability of SPARQL Endpoints in Linked Open Data but I didn't see a straight-forward way of finding the version.
The first thing that you should check is that when you're dereferencing the endpoint, you're asking for content in an RDF format, not the text/html, etc., that a web browser would specify by default, and that the endpoint isn't giving you certain outputs based on the user agent, etc. For instance, if you visit the DBpedia endpoint at http://dbpedia.org/sparql, you get an HTML query editor. However, if you request that page with the Accept header set to "application/rdf+xml", you'll get the service description. Without knowing what endpoints you're having trouble with, we can't really be much more help. This should work, but some endpoint doesn't do it, that's not really a technical problem that we can debug, especially if you don't tell us which endpoints you have problems with. Here's what this looks like using curl:
$ curl -H "Accept: application/rdf+xml" http://dbpedia.org/sparql
<?xml version="1.0" encoding="utf-8" ?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:sd="http://www.w3.org/ns/sparql-service-description#" >
<rdf:Description rdf:about="http://dbpedia.org/sparql">
<rdf:type rdf:resource="http://www.w3.org/ns/sparql-service-description#Service" />
<sd:endpoint rdf:resource="http://dbpedia.org/sparql" />
<sd:feature rdf:resource="http://www.w3.org/ns/sparql-service-description#UnionDefaultGraph" />
<sd:feature rdf:resource="http://www.w3.org/ns/sparql-service-description#DereferencesURIs" />
<sd:resultFormat rdf:resource="http://www.w3.org/ns/formats/SPARQL_Results_JSON" />
<sd:resultFormat rdf:resource="http://www.w3.org/ns/formats/SPARQL_Results_XML" />
<sd:resultFormat rdf:resource="http://www.w3.org/ns/formats/Turtle" />
<sd:resultFormat rdf:resource="http://www.w3.org/ns/formats/N-Triples" />
<sd:resultFormat rdf:resource="http://www.w3.org/ns/formats/N3" />
<sd:resultFormat rdf:resource="http://www.w3.org/ns/formats/RDF_XML" />
<sd:resultFormat rdf:resource="http://www.w3.org/ns/formats/SPARQL_Results_CSV" />
<sd:resultFormat rdf:resource="http://www.w3.org/ns/formats/RDFa" />
<sd:supportedLanguage rdf:resource="http://www.w3.org/ns/sparql-service-description#SPARQL10Query" />
<sd:url rdf:resource="http://dbpedia.org/sparql" />
</rdf:Description>
Here's a live version that uses d3's XmlHttpRequest functionality. (I know you can do this without libraries, but I've been using a lot of d3 lately.)
/**
* Make a GET request to dbpedia.org/sparql
* and show the response in a PRE element.
*/
d3.xhr("http://dbpedia.org/sparql")
.get(function(error,data) {
console.log(error);
console.log(data);
d3.select("body")
.append("pre")
.text(data.response);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>

S3 Redirect base domain to key prefix folder

I'm using an S3 bucket to host a static site mydomain.com. Originally the blog content layout was
index.html
posts/article.html
Now I keep all the blog content inside a blog directory.
blog/index.html
blog/posts/article.html
I have enabled website hosting on mydomain.com bucket. I would like to use S3's custom redirection rules to redirect old urls which lacked the 'blog' prefix. For example, mydomain.com/index.html should redirect to mydomain.com/blog/index.html.
I've tried
<RoutingRules>
<RoutingRule>
<Condition>
<KeyPrefixEquals>/</KeyPrefixEquals>
</Condition>
<Redirect>
<ReplaceKeyPrefixWith>blog/</ReplaceKeyPrefixWith>
</Redirect>
</RoutingRule>
</RoutingRules>
and
<RoutingRules>
<RoutingRule>
<Condition>
<KeyPrefixEquals>mydomain.com/</KeyPrefixEquals>
</Condition>
<Redirect>
<ReplaceKeyPrefixWith>mydomain.com/blog</ReplaceKeyPrefixWith>
</Redirect>
</RoutingRule>
</RoutingRules>
but the first results in a redirection loop (not surprising) and the second does not work.
Check if following hack works - Add "HttpErrorCodeReturnedEquals=404" to the condition. I am expecting following sequence of events to happen
Access "www.example.com/index.html"
Gets 404 as page doesn't not exists
Your prefix condition along with 404 matches a
Redirect rule
So "/blog" should be added as prefix
Returns "www.example.com/blog/index.html" page.
Reading documentation I did not find a way to specify negative condition like "KeyPrefixNotEquals" to avoid the recursion
You need to use the Redirect Rules and add in the ReplaceKeyPrefixWith item:
<RoutingRules>
<RoutingRule>
<Redirect>
<Protocol>https</Protocol>
<HostName>mydomain.com</HostName>
<ReplaceKeyPrefixWith>blog/</ReplaceKeyPrefixWith>
<HttpRedirectCode>301</HttpRedirectCode>
</Redirect>
</RoutingRule>
</RoutingRules>
NOTE: Some browsers cache can be very sticky so ensure that you either use a different browser session to check your redirect rules or close and reopen the browser to check.

Pass "dot slash" sequence in a URL querstrying

In the ASP.net web application that I am working on, there is a link like below
INFCE/DEP./WG--8/48
When I click on the link, it gives a File not found (404) error. I did a bit of research and believe that it is the presence of "./" (dot-slash) sequence in the link which is causing this error.
I tried encoding the link as below (though period is OK in a URL)
INFCE/DEP./WG--8/48
But, it did not help. It still gives me the same error. Any ways to overcome this?
It looks to me like you shouldn't have those %22 in there. %22 is ascii char for quote. I think that might be hosing you.
IIS 7.5 has rules to filter character sequences that appear in a querystring. The dot-slash was one of them, which is a potential security threat. It can be overcome by adding the below tag in the web.config under <security>
<requestFiltering>
<denyQueryStringSequences>
<remove sequence="./"/>
</denyQueryStringSequences>
</requestFiltering>

Problems with Zend_Service_Amazon_Simpledb and specialchars

I want to copy some data from MySQL to SimpleDB with the Zend Framework. It works fine so far, but if any attribute contains special chars like "äöüß" the server refused my request with "The request signature we calculated does not match the signature you provided.".
SimpleDB accept the request, if all specialchars are encoded in some way, but I want it like it is. What can I do to solve that? I tried to find informatione in google, but I found no solution.
I found a solution for that problem, but I had to change some code in Zend_Service_Amazon_SimpleDb. There was a missing http-header in the request. Just add
$request->setHeaders('Content-Type', 'application/x-www-form-urlencoded; charset=utf-8');
in _sendRequest().