Redirect parameters . htaccess

Asked

Viewed 322 times

-2

I would like to know how to redirect a url with parameters on .htaccess . I have a URL that can receive several parameters and I want to redirect it to another page with these parameters.

The page is wp-login.php, I have to redirect to the page /login/. But I need to redirect all the parameters, not just the page. ex:

http://site.com/wp-login.php?para=ola
http://site.com/login?para=ola

http://site.com/wp-login.php
http://site.com/login



RewriteRule ^/wp-login.php$ /login [QSA,L]
  • 2

    There is an absurd amount of questions about it here on the site, see which helps you best: http://answall.com/search?tab=votes&q=url%20amigavel%20htaccess

  • The redirect is so internal, want to redirect or rewrite the urls? If you are going to rewrite the way you did, send the GET parameters normally. Explain better what the problem is.

  • @Guilhermenascimento I would like to redirect, but the login URL has to receive the parameters that were in the other URL... 'Cause if it has parameters, it doesn’t redirect... I have to redirect everything... and send the parameters from one to the other...

  • Look I think maybe you’re confusing the term redirect, we go by parts, you want when access /wp-login.php show the content of /login right?

  • I have the wordpress. The login page is: wp-login.php... I created another page called /login/ , I need to redirect the first one to this... because the way I did above it does not redirect when it has the parameters and does not send the parameters to the other page...

  • @abcd should write this in the question, and another the example you added was not clear, you mixed in the middle of the code, see questions that have high score to see how people write and write better their own, understand as a constructive criticism. I’m answering your question.

  • @abcd it may be sending yes, the problem may be in your form too.

  • @Guilhermenascimento I sincerely do not understand, nothing else is working, neither the way I described nor your...

  • As I said and repeat again, two things: Either you didn’t understand the difference of redirecting and rewriting, or the problem is in your form (does the HTML part know?) or else a third, the . htaccess is not in the right place or you are not using Apache, lack much information to determine the cause of your problem.

  • @Guilhermenascimento There is something in wordpress that is hindering me to accomplish what I wish. The solution was to use functions of wordpress itself.

Show 5 more comments

2 answers

1


What you want is even redirect, which is different from rewriting, the way you did . htaccess it only serves for when accessing:

http://exemplo/wp-login.php?teste=1

Will display the content of:

/wp-login.php?teste=1

For same redirects, where will change the URL in the browser, you need to use the flag R= as documented https://httpd.apache.org/docs/current/rewrite/flags.html#flag_r

Something else to regex sometimes has to escape some characters like . and -, also should not start with /, you may also have forgotten the RewriteEngine On, should look like this:

RewriteEngine On
RewriteRule ^wp\-login\.php$ login [QSA,L,R=302]

If /login is a folder do so to avoid more than one redirect:

RewriteEngine On
RewriteRule ^wp\-login\.php$ login/ [QSA,L,R=302]

I tested it here and it worked with GET.

0

The solution found by me and that worked in wordpress, was the use of native functions. because in . htaccess did not work:

add_action('init','custom_login');

function custom_login(){
    global $pagenow;
    if( 'wp-login.php' == $pagenow ) {
        wp_redirect('login');
        exit();
    }
}
  • But this does not send the querystring, if your code worked like this is because the problem is another and you could not explain friend. Understand as a constructive criticism ok? See you

  • @Guillhermenascimento doesn’t really send... But for what I’ve been analyzing, it’s unnecessary to send the query, because the plugin automatically redirects to the desired page... But it worked out the code above... Thank you and until next... ATT

Browser other questions tagged

You are not signed in. Login or sign up in order to post.