Anton
Anton

Reputation: 117

Wordpress redirect htaccess

I have a problem with my htaccess file in wordpress. I want to redirect users who come to /wp-login.php?action=register to another registration form with role parameter. Like this /wp-login.php?action=register&role=patient. So i wanna hide first url from users. I wrote this line in my htaccess.

RewriteRule ^wp-login.php?action=register$ /wp-login.php?action=register&role=patient [NC,L]

It's located here in my file:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /
RewriteRule ^wp-login.php?action=register$ /wp-login.php?action=register&role=patient [NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

</IfModule>

And i have no effect with that. What am i doing wrong here?

Upvotes: 1

Views: 1487

Answers (3)

Victor Misa
Victor Misa

Reputation: 1

Thank you for sharing the problem and solution related to the use of .htaccess in WordPress installations. I understand the issue you're describing. It can indeed be a problem when your WordPress installation is located in a directory called "Wordpress-xxxx" instead of the root directory, and the provider uses a redirect to make it appear as if the website is directly accessible from the root.

I've encountered a similar problem on my website. In my case, the WordPress installation was also in a subdirectory, causing issues with the .htaccess configuration and resulting in 404 errors for certain pages. Unfortunately, modifying the .htaccess file in the root directory was restricted by the hosting provider for security reasons.

To resolve this problem, it is necessary to contact the hosting provider and request them to synchronize both .htaccess files. The .htaccess file in the WordPress directory should be copied or overwritten to the one in the root directory. This ensures that the correct rewrite rules and configurations are applied, allowing visitors to access the website and its pages without encountering 404 errors.

If you're experiencing a similar issue, I recommend reaching out to your hosting provider and explaining the situation to them. They should be able to assist you in synchronizing the .htaccess files and resolving the problem.

Upvotes: 0

hans
hans

Reputation: 1

Another problem and solution involves htaccess: When you have your website at a host provider from which you obtain Wordpress installation, it can occur that your WP is not in the root directory, but in a directory called Wordpress-xxxx

For instance: your website address is : http://website.com

so your path is: http:/website.com/wordpres-xxx/file xxx However, most providers use in the background a redirect so it seems to your visitor goes directly to http://website.com

For htaccess this is a problem. If you look in your WP directory you will find htaccess and a good change it has the right format. But, there is another htaccess on your root. Often you cannot change this one, because your provider blocks it for any modification for safety reasons.

That is why your visitors cannot find your pages on your website (404) because that htaccess file in your root, did not change.

You have to ask your provider to sync both htaccess files. the one in WP should be copied/ overwrite the one in your real root directory.

that would solve the problem

Upvotes: 0

aorcsik
aorcsik

Reputation: 15552

You have to match for the query string in a RewriteCond:

RewriteCond %{QUERY_STRING}  ^action=register$
RewriteRule ^wp-login[.]php$ /wp-login.php?action=register&role=patient [R,NC,L]

Edit: corrected my answer

Upvotes: 1

Related Questions