How to redirect one url to another url?


Tech_sharma:

My app url is: http://219.41.192.244:8080/KanaApp/login - it will require user login page

Login is the first page, then only the user can access the application.

However, if the user enters that URL - http://219.41.192.244:8080/KanaApp , it redirects to http://219.41.192.244:8080/KanaApp/#/home and allows the user to enter without logging in home page. How can I prevent this and make the login page mandatory?

Whenever the user puts this URL as http://219.41.192.244:8080/KanaApp , I want to redirect to http://219.41.192.244:8080/KanaApp/login URL, can someone help me here.

Spring Boot application: I set the context path here server.contextPath=/KanaApp

and at the front corner

    SecurityConfig class:

    .antMatchers("/static/**").permitAll()
        .antMatchers("/assets/**").permitAll()
        .antMatchers("/css/**").permitAll()
        .antMatchers("/forgotPassword").permitAll()
        .antMatchers("/setForgotPassword").permitAll()
         .and()
            .formLogin()
            .successHandler(handler)
            .usernameParameter("username")
            .passwordParameter("password")
            .loginPage("/login").permitAll()
        .and()
            .logout()
            .logoutSuccessUrl("/login?logout")
            .invalidateHttpSession(true).permitAll()
        .and()
        .csrf().disable();
Le Town :

I think what you are missing is proper security configuration. If you want to connect a user, you must force the user to connect. Means you must only allow requests to authenticated users. Here you will find many guides on how to execute the example .

What you need to do is register an extension class WebSecurityConfigurerAdapterand define which part of the application is protected. E.g:

.antMatchers("/public/**").permitAll()
.anyRequest().authenticated()

Meaning all uris in /public/... will be available to everyone, so you don't need to be logged in to get to that directory, and anyone else needs to be logged in to that directory.

When you have a login page, the basic way to force the user to that page is to implement a spring form login (explained in more detail in the previous link). it's part of the job

.formLogin()
.loginPage("/login")
.permitAll()

After declaring spring secure form login, all requests that must be authenticated will be redirected to the page specified here. Of course you can customize this page to your needs ( example from spring documentation ).

Related


How to redirect one url to another url?

Tech_sharma: My app url is: http://219.41.192.244:8080/KanaApp/login - it will require user login page Login is the first page, then only the user can access the application. However, if the user enters that URL - http://219.41.192.244:8080/KanaApp , it redire

How to redirect one page url to another

sudhakaranR87 I want to redirect one page to another page like below. http://dev . ****. in:82/abc/wp redirects to http://dev . ****. in: 82/abc/blog I have tried the following code on .htaccess with no luck. RewriteEngine On RewriteCond %{HTTP_HOST} ^dev\.xx

How to redirect one page url to another

sudhakaranR87 I want to redirect one page to another page like below. http://dev . ****. in:82/abc/wp redirects to http://dev . ****. in: 82/abc/blog I have tried the following code on .htaccess with no luck. RewriteEngine On RewriteCond %{HTTP_HOST} ^dev\.xx

How to redirect one page url to another

sudhakaranR87 I want to redirect one page to another page like below. http://dev . ****. in:82/abc/wp redirects to http://dev . ****. in: 82/abc/blog I have tried the following code on .htaccess with no luck. RewriteEngine On RewriteCond %{HTTP_HOST} ^dev\.xx

How to redirect one page url to another

sudhakaranR87 I want to redirect one page to another page like below. http://dev . ****. in:82/abc/wp redirects to http://dev . ****. in: 82/abc/blog I have tried the following code on .htaccess with no luck. RewriteEngine On RewriteCond %{HTTP_HOST} ^dev\.xx

How to redirect one page url to another

sudhakaranR87 I want to redirect one page to another page like below. http://dev . ****. in:82/abc/wp redirects to http://dev . ****. in: 82/abc/blog I have tried the following code on .htaccess with no luck. RewriteEngine On RewriteCond %{HTTP_HOST} ^dev\.xx

How to redirect one URL to another using web.config?

day field I want to redirect https://www.test.com/flights/economy-class-flights to https://www.test.com/flight-types/economy-class I have tried something similar to the following without success. <rule name="Redirect 1" stopProcessing="true"> <match url="h

How to redirect one URL to another using web.config?

day field I want to redirect https://www.test.com/flights/economy-class-flights to https://www.test.com/flight-types/economy-class I have tried something similar to the following without success. <rule name="Redirect 1" stopProcessing="true"> <match url="h

How to permanently redirect from one base URL to another in IIS 7

Suhas I have a website hosted on IIS7 which is configured with the following two host headers members.company1.com members.company2.com I now need to permanently redirect members.company1.comto members.company2.com. I know how to redirect the full URL to anot

How to create redirect from one page url to another in drupal 8

Mark Bucknell Question: I have 2 pages in my Drupal 8 site, let's call them "/page/1" and "/page/2". I need to force a redirect on "/page/1" so that it goes to "/page/2". How can I do this through the interface? What I've tried: . I tried using the standard re

How to redirect one URL to another using web.config?

day field I want to redirect https://www.test.com/flights/economy-class-flights to https://www.test.com/flight-types/economy-class I have tried something similar to the following without success. <rule name="Redirect 1" stopProcessing="true"> <match url="h

How to permanently redirect from one base URL to another in IIS 7

Suhas I have a website hosted on IIS7 which is configured with the following two host headers members.company1.com members.company2.com I now need to permanently redirect members.company1.comto members.company2.com. I know how to redirect the full URL to anot

Wordpress: How to redirect feed URL to another URL?

Ramon K. I have a blog built with Wordpress where I host a podcast. iTunes is currently reading RSS from URL "A" ( http://ramonkayo.com/categoria/hashcast/feed ), but I want it to read RSS from URL "B" ( http://ramonkayo.com/feed/podcast ) read in RSS ). How t

Redirect one URL to another using regex?

Annie I want to redirect all requests to http://www.example.com/category/ * redirect to http://www.example.com . Here is what I tried: RewriteRule http://www.example.com/category/.* http://www.example.com [R=301,L] Unfortunately, this doesn't work. Any ideas

htaccess redirect one url to load from another url

whitesova93 I'm trying to redirect one of the URLs in my site and I'm getting an error 404 not found, but I'm trying to redirect this URL : http://www.stoikovstroi.com/bg/противопожарни-врати Can be loaded from this one : http://www.stoikovstroi.com/vina/index

htaccess redirect one url to load from another url

whitesova93 I'm trying to redirect one of the URLs in my website and I'm getting an error 404 not found, but I'm trying to redirect this URL : http://www.stoikovstroi.com/bg/противопожарни-врати Can be loaded from this one : http://www.stoikovstroi.com/vina/in

How to redirect request to another url on json server?

NameTopSecret I need to request paginated data from json server. I want to retrieve a user page, where each page contains 10 results. For this, I GETsend a request to /posts/page/1, but I know I need to request like /posts?_start=0&_end=9this because that's ho

How to redirect request to another url on json server?

NameTopSecret I need to request paginated data from json server. I want to retrieve a user page, where each page contains 10 results. For this, I GETsend a request to /posts/page/1, but I know I need to request like /posts?_start=0&_end=9this because that's ho

How to redirect to another URL after setting frame

Keane Allen I have an index.php file with a frameset. My question is how to redirect to homepage.php? I've tried header("Location: homepage.php"); it works for me but only shows up in I set the frame. I want to show it in full window. thanks. Ryan Pendleton Si

How to redirect request to another url on json server?

NameTopSecret I need to request paginated data from json server. I want to retrieve a user page, where each page contains 10 results. For this, I GETsend a request to /posts/page/1, but I know I need to request like /posts?_start=0&_end=9this because that's ho

How to redirect request to another url on json server?

NameTopSecret I need to request paginated data from json server. I want to retrieve a user page, where each page contains 10 results. For this, I GETsend a request to /posts/page/1, but I know I need to request like /posts?_start=0&_end=9this because that's ho

How to redirect request to another url on json server?

NameTopSecret I need to request paginated data from json server. I want to retrieve a user page, where each page contains 10 results. For this, I GETsend a request to /posts/page/1, but I know I need to request like /posts?_start=0&_end=9this because that's ho

How to redirect to another URL after setting frame

Keane Allen I have an index.php file with a frameset. My question is how to redirect to homepage.php? I've tried header("Location: homepage.php"); it works for me but only shows up in I set the frame. I want to show it in full window. thanks. Ryan Pendleton Si

How to redirect to another URL after setting frame

Keane Allen I have an index.php file with a frameset. My question is how to redirect to homepage.php? I've tried header("Location: homepage.php"); it works for me but only shows up in I set the frame. I want to show it in full window. thanks. Ryan Pendleton Si

How to redirect a URL to another URL using /etc/hosts

Heisenberg I want to block some sites on my ubuntu system. So, I am /etc/hostsin. 127.0.1.1 www.reddit.com 127.0.1.1 www.facebook.com This successfully blocks the site now, but when I go to one of the URLs mentioned above, I want to redirect to an