Redirection in .htaccess

I want to redirect

/wp-login.php?action=register

to

/become-member/

This is how it looks like in my .htaccess file. The underlined code is the new one.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
[U]RewriteRule ^become-member/$ /wp-login.php?action=register[/U]
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

But this do not work. What I am doing wrong. Beside this changing in .htaccess do I need to think about something more?

Hi, and welcome to SitePoint :wave:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
[U]RewriteRule ^become-member/$ /wp-login.php?action=register[/U]
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

First of all, remove the <IfModule mod_rewrite.c> and </IfModule> lines. Check once to see if mod_rewrite is working, and if it is, there really is no need asking Apache about it every time.

Also, since you don’t have any of the Redirect* directives in there, you don’t need the RewriteBase /

Now for your problem.

First of all the position where you placed the new rule is incorrect. Swap it around it comes before the first RewriteCond.
The thing is that RewriteConds belong to the first RewriteRule that comes after it. So in your case they belonged to the rule you wrote, while they should have stayed with the rule wordpress generated.


RewriteEngine On
RewriteRule ^index\\.php$ - [L]
[U]RewriteRule ^become-member/$ /wp-login.php?action=register[/U]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Lastly, add an [L] flag to that for more efficient processing


RewriteEngine On
RewriteRule ^index\\.php$ - [L]
RewriteRule ^become-member/$ /wp-login.php?action=register [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

The last thing you need to do now is change the URL /wp-login.php?action=register to become-member/ in your website, and you’re all set :slight_smile:

Thanks I did that now.

But where do I change the URL /wp-login.php?action=register to become-member/ in my website?

I use Wordpress. I can’t access the /wp-login.php?action=register from the admin area.

But i found this in wp-register.php

<?php
/**
 * Used to be the page which displayed the registration form.
 *
 * This file is no longer used in WordPress and is
 * deprecated.
 *
 * @package WordPress
 * @deprecated Use wp_register() to create a registration link instead
 */

require('./wp-load.php');
wp_redirect('wp-login.php?action=register');

?>

Should I change something here?

You don’t need to change anything in your code.

Basically the browser should show /become-member/, but your server will think they’re on wp-login.php…

Also, if you notice this little comment:


* This file is no longer used in WordPress and is
* deprecated.

it means that file doesn’t actually do anything any more. It’s just there for backwards compatibility.

So why don’t it redirect then if I have this

RewriteEngine On
RewriteRule ^index\\.php$ - [L]
RewriteRule ^become-member/$ /wp-login.php?action=register [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

What is wrong? So if I don’t need to change any coding, then what more do I need to do?

Just to be clear, can you please explain in detail what the site is doing now and what you would like it to do?

Ok, my site was deindexed by google, and one of the reason was that this article “plugin” that I am using for WP is used by many other users. Therefor to many users has the same /wp-login.php?action=register and this makes my site not unique.
This is the information I got from other peoples.

There could be other reasons why my site is deindexed, but I need to start with this one.

Okay, then you’d need to edit the wordpress code after all.

What the .htaccess is doing, is that if people request /become-member in their browser, it will serve /wp-login.php?action=register

What it doesn’t do is redirect people who request /wp-login.php?action=register to /become-member.

So it’s up to you to change the link in wordpress from /wp-login.php?action=register to /become-member

There is no way that your wp-login.php page was the cause of you being removed from Google… are you sure you aren’t copying other content?

Well my site is a article directory. So members where able to publish article without my permission. But now this is locked.

This can be why my site is penalized by google.

Thanks for helping me.