Redirection to incorrect page - xpages

I am trying to redirect using a button on a custom control (code below). the following is written to the debug toolbar which is where I want to go:
destBack=https://www.example.com/MyAttachments . But I instead get a Error 404 page and the following line appears on the server console:
HTTP Web Server: Item Not Found Exception [/site/home.nsf/https:/www.example.com/MyAttachments.xsp] Anonymous
I do have a reditection rule as follows:
Description: MyAttachmentsView
Type of rule: Redirection
Incoming URL pattern: */MyAttachments
Redirect to this URL: /site/home.nsf/MyProfileAttachmentsView.xsp
Send 301 Redirect:
If I copy and paste the destBack URL I get where I want to go.
My SSJS code behind the button is as follows
importPackage(com.example);
var destination = configBean.getValue("HostURL")+"MyAttachments";
dBar.info("destBack="+destination)
context.redirectToPage(destination)

Try this code to redirect
externalCtx = facesContext.getExternalContext();
externalCtx.redirect("http://www.tlcc.com");
See http://linqed.eu/2011/07/27/xpages-server-vs-client-side-redirects/

context.redirectToPage is designed to redirect the XPages runtime to an XPage within the current database. That's why the URL in the error message contains "/site/home.nsf/" (the current database path) and "https:/www.example.com/MyAttachments.xsp" (the URL you're defining).
If you want to change the whole URL, you need to change the URL client-side, not server-side, e.g. with location.href="...."

Related

Redirect http to https via IIS

I have this application that I just installed a SSL certificate for. Yest I tried to redirect the users to use only the HTTPS://url.com. and prevent them from using the http://url.com site. However because I lack understanding the regular expressions to define the Pattern and the condition and unfortunately, I could not find a guide with some example of how to define those rules. I would like a concrete example of how to set this up https://{HTTP_HOST}{REQUEST_URI}.
Ensure you have the URL Rewrite feature added. In IIS manager configure the following in the URL rewrite section.
Create inbound rule (Blank Rule)
Requested URL : Matches the pattern
Using: Wildcards
Pattern: *
Conditions
Input: {HTTPS}
Type: Matches the pattern
Pattern: off
Action
Action Type: Redirect
Redirect URL: https://{HTTP_HOST}{REQUEST_URI}
Append Query String Checked
Redirect type: Found (302)
Once you have done this. Create a condition...
Right click your new rule
Conditions -> Add+
Condition Input : {QUERY_STRING}
Matches the Pattern
Pattern: off
Essentially it should look like this:
All traffic using a http request will be automatically redirected to the https port.
I think I've found a solution without url rewrite. In IIS, right click on the website, choose "Manage web site - Advanced settings", expand "Behaviour", expand "HSTS" and set to "True" the properties "Enabled" and "RedirectHttpToHttps".
Update:
As #jonasfh pointed out, you need anyway to have bindings both to http and https, because only the successful requests to http are redirected to https. So, if the request to http isn't successful (because http binding is not present) the redirect to https doesn't happen. Thank you.
Update2: just wanted to add that after the settings a site restart from IIS is needed.
My method from Global.asax
protected void Application_BeginRequest()
{
#if !DEBUG
if (!Context.Request.IsSecureConnection)
{
if (Context.Request.Url.ToString().Contains(".well-known")) return;
Response.StatusCode = 301;
Response.RedirectPermanent(Context.Request.Url.ToString().Replace("http:", "https:"));
}
#endif
}

Proper way to redirect to a different page in Hybris

what is the proper way to redirect to a different page in Hybris?I have been the following approach quite a lot:
link
But some people emphasized that it is better to redirect using a separate method and using redirect:
What is the correct way?
Let me first tell you basic difference between request Redirect Vs Forward.
Redirect: Server sends a header (in response) back to the browser/client, which contain redirect URL, then browser initiates a new request to redirect URL.
When can we use Redirect?
Usually, when data is posted to the server, we should redirect to get method(URL) to prevent data resubmission on browser refreshed(F5).
return "redirect:/redirectToGeturl";
Forward: Within the server, control can be forwarded to target resource(URL). Which is done by container internally so browser/client is not aware of it.
When can we use forward?
Sometimes, we want to show different page/resource in response without changing original URL, then we forward request to other controller internally.
return "forward:/404";
What is the proper way to redirect to a different page in Hybris?
public static final String REDIRECT_PREFIX = "redirect:";
public static final String FORWARD_PREFIX = "forward:";
This class level constants are defined in AbstractController. You can use that by extending your controller to AbstractPageController or AbstractController.
return REDIRECT_PREFIX + "/redirecturl";
return FORWARD_PREFIX + "/404";
< a href="< c:url value="/path" />">link< /a >
This is the correct way to declare a link on client/browser side, which sends GET request to /path once the user clicks it.
Find detail post here

Showing a notice when site fails to load completely

Sometimes during overload some sites fail to load.
I can detect this error using chrome.webRequest.onErrorOccurred api.
I guess the content script will not run at all in this case so sending message from background page to content script is of no use.
How can I paste a notice in the site body that it has failed to load?
Maybe using script execute from the background page? Will the page have a body content?
You've got a few options here. If you're using chrome.webRequest.onErrorOccurred() though I'd suggest you redirect the tab to an error page when an error occurs, using chrome.tabs.update().
For example:
chrome.webRequest.onErrorOccurred.addListener(function(details)
{
chrome.tabs.update(details.tabId, {url: "URL FOR AN ERROR PAGE"});
},
{types: ["main_frame"]});
This will redirect the tab the error occurred in when a web request with a resourceType of main_frame errors.
There are a few things you need to consider here. Do you only want to capture errors from requests with a type of main_frame? If not, just remove the 'types' filter from the event.
The other thing you need to consider is what page you're redirecting to. You can package a HTML file within your extension and then redirect to that. To generate the URL of your error page you can run chrome.extension.getURL('customerrorpage.html').

Get Page URL on 404 IIS Redirection (Custom Error Page in Classic ASP)

I have implemented IIS Redirection on 404 error code and created a Custom Error Page for it. My Custom error page is written in classic asp (e.g: FileNotFound.asp). I need to write the URL of calling page (which does not exists) in my Custom Error Page.
You need the following:
Request.ServerVariables (server_variable)
Replace it with:
Request.ServerVariables (HTTP_REFERER)
That should work. Article on it at w3Schools: http://www.w3schools.com/asp/coll_servervariables.asp

Routes in Codeigniter

I want to have a clean URL in CodeIgniter based application for User's Profile Information.
Please Take a look at URL formats below.
Actual URL : http://www.mydomain.com/index.php/users/profile/user1
I'm expecting users to have Personal URL's like
http://www.mydomain.com/user1
http://www.mydomain.com/user2
http://www.mydomain.com/user3
URL http://www.mydomain.com/user1 should process http://www.mydomain.com/index.php/users/profile/user1 in background execution.
I will be removing index.php from URL using Route library.
Thanks in advance for any sort of help.
Have a look at https://www.codeigniter.com/user_guide/general/routing.html.
$route['user(:num)'] = "users/profile/user/$1";
If you mean you want /anyusername to route to the users controller, you would have to put:
$route['(:any)'] = "users/profile/$1";
At the bottom of routes.php and every non user-URL above it. Otherwise every URL would be routed there, obviously. You will need to implement some mechanism in the users-controller to throw 404-errors, since you are routing all requests not catched in the routing rules above.
IN config/routes.php
add this line
$route['user(:num)'] = "users/profile/$1";

Resources