I'am using play framework 2.6 with scala, I want to prevent accessing my web pages from url .In the usual case if i write the URI pattern in the url it will redirct to the web page by executing the associated action ,for example if i write in the url : http://localhost:9000/home it will redirect to the home page, but what i want is to redirect to error page rather than the home page when writing an URI (in this case: /home) in the url.
my routes file
GET /home controllers.HomeController.index()
You can redirect in the controller method:
# my routes file
GET /home controllers.HomeController.errorRedirect()
# HomeController
...
def errorRedirect = Action {
Redirect("/error")
}
or perhaps you want to catch all and then redirect:
# my routes file
GET /home controllers.HomeController.home()
GET /*path controllers.HomeController.errorRedirect()
See also: supplying a custom error handler in the play docs.
Related
We have a multi-site environment where each site has its own redirect URL. We want to use a single Client ID and Secret for our application but register multiple redirect URIs to it. Is it possible to add multiple URLs in below registration form:
I don't think there is possible solution to add on multiple URLs on the SharePoint online app registration form.
But from what i understand there is another way to achieve use a single Client ID and Secret for application and perform multiple redirects.
You can control the redirect url using the appredirect.aspx by specifying the redirect_uri parameter if you need to redirect from the default one check here for reference.
Basiclly it call the subsite page containing the below JS to install the app.
var url = String.format(
"{0}/_layouts/15/appredirect.aspx?client_id={1}&redirect_uri=https://***.azurewebsites.net/<<controller>>/<<view method containing the code to install the app>>?{{StandardTokens}}",
<<subsite url>>, "<<client id>>");
window.location.href = url;
The above javascript calls the appredirect.aspx page which then calls the app site as below,
https://****.azurewebsites.net/home?SPHostUrl=<<subsiteurl>>&SPLanguage=en-US&SPClientTag=1&SPProductNumber=**&SPAppWebUrl=<<weburl>>
Note: The above can be extended to check for the successful installation of the app and display an error message accordingly.
SPWeb.LoadAndInstallWeb equivalent REST / Javascript CSOM is also available here.
Here are some relevant links:
Use the redirect URL in an add-in that asks for permissions on the fly
Redirect URIs and a sample redirect page
How can I add redirects to my Storyblok project when it is using the Silex Boilerplate?
You can redirect to another page by returning a RedirectResponse response, which you can create by calling the redirect method:
app->get('/{{entry_path}}', function () use ($app) {
return $app->redirect('/{{exit_path}}');
});
http://silex.sensiolabs.org/doc/2.0/usage.html#redirects
When you want to delegate the rendering to another controller, without a round-trip to the browser (as for a redirect), use an internal sub-request (Don't use this if you really want to redirect your page). We provide such an forward in the app.php for the /home slug already, so /home page would be accessible on / without redirecting but doing a subrequest.
Is there a default catch all fallback route in Play framework? If so how can I configure it in my routes file? Currently, there are some urls that I do not want the user to call them and even if they call, I don't want that error page appearing, rather I want them to go to the landing page of my web app! Is there a way to do that in the routes configuration file?
Simply define a route matching any path at the end of your routes file. Do not forget to define specific routes for your assets though, for example:
GET / controllers.Application.index
GET /some/path controllers.Application.someHandler
...
# End of file
GET /favicon.ico controllers.Assets.at(path="/public", file="img/favicon.ico")
GET /$file<(css|img|js|partials)/.*> controllers.Assets.at(path="/public", file)
GET /$path<.*> controllers.Application.catchall(path)
Any URL not matched by an earlier rule will be matched by this one.
Catch all routes makes sense when you want to do something with the path (ie. resolve it manually in your custom action), otherwise it's enough to use common onHandlerNotFound in your Global object and redirect request wherever you want.
I'm using Symfony 1.4 to build a web application. The home page action for this application is as follows.
Module = content
Action = indexAction.php
/localhost/myapp/web/index.php/content/
I need to use this action as the defalut action when someone access the application folder using web browser. If someone access the myapp folder as follows.
/localhost/myapp
It should internally redirect to the
/localhost/myapp/web/index.php/content/
and access the homepage.
I guess Symfony routing will not work here. Can someone help me on this.
Using the symfony routing system, you can define the default module / action for the /.
In the myapp/config/routing.yml, define the homepage route (it's defined by default):
# default rules
homepage:
url: /
param: { module: content, action: index }
This way, accessing /myapp won't redirect you but you will be on your homepage.
Well, say I have a number of html pages in my web. The case is that I´m doing changes sometimes in the directory structure, so when anybody try to access to a determinated URL, it's possible that such URL does not exit. The files names don't change but so do the paths.
As far as I now, the server takes the user to a "404" page that can be customized. Is possible to customize the page in this way?:
The user tries oneweb.com/oldpath/page.html; which does not exist.
A 404 customized page is launched
404 page runs an script IS THIS POSSIBLE?
The script is given the name of the file WHERE IS STORED SUCH NAME?
The script search the entire directory structure to find page.html HOW TO ACCESS TO THE STRUCTURE
The file is found and the new URL is stored: oneweb.com/newpath/page.html
a link appears showing the new URL
Maybe this process is relatively common and I can find some related code or tutorial?
Are you using Apache? Linux?
Add a 404 handler
ErrorDocument 404 /404.php
Then use 404.php to parse the url. This simple example just grabs everything after the last / in the URI so http://example.com/foo/bar/page.html would put page.html in $url:
$url = end(explode('/', $_SERVER['REQUEST_URI']));
Then use one of the comment example functions in http://php.net/manual/en/function.readdir.php to search your directory and find the file.
Then do a header 301 redirect
header ('HTTP/1.1 301 Moved Permanently');
header ('Location: http://example.com/' . $file_path);