I'm trying to do something specific here, that may be a little complicated and I can't figure out how to do it.

This is what I have with htaccess:

RewriteOptions inherit
RewriteCond %{HTTP_HOST} ^homepageA\.ar$ [OR]
RewriteCond %{HTTP_HOST} ^www\.homepageA\.ar$
RewriteRule ^/?$ "https\:\/\/homepageB\.ar\/" [R=301,L]

-User enter to homepageA -> user is automatically redirected homepageB

homepageB includes a "home" menu button pointing to homepageA, so of course touching that button redirects to homepageB again. But I need to avoid this. I need that users on homepageB can go to the "old" homepageA without the redirection to the new homepageB.

Is there a way to achieve this? Or a way to append something on a link that avoids htaccess redirection (so I can modify the "home" button link accordingly)?

Thanks in advance!

  • What directives are you "inheriting"?
    – MrWhite
    Commented May 25, 2021 at 9:53

1 Answer 1


A quick way might be to simply append a query string to the URL in order to prevent the redirect (eg. ?noredirect) - simply appending a query string should not prevent the old homepageA from displaying.

You'll presumably want to prevent indexing of the ?noredirect URL. This can be achieved by sending an X-Robots-Tag: noindex HTTP response header.

However, any user typing this URL (ie. ?noredirect) will be able to access the old homepageA, regardless of whether they have visited homepageB first.

For example:

# Redirect homePageA to homepageB, when the query string is not "noredirect"
RewriteCond %{QUERY_STRING} !^noredirect$
RewriteCond %{HTTP_HOST} ^(www\.)?homepageA\.ar
RewriteRule ^$ https://homepageB.ar/ [R=301,L]

# Send the X-Robots-Tag noindex header when query string is "noredirect"
RewriteCond %{QUERY_STRING} ^noredirect$
RewriteRule ^ - [E=NOINDEX:1]
Header set X-Robots-Tag "noindex" env=REDIRECT_NOINDEX

There's no need to backslash-escape colons, slashes and dots in the RewriteRule substitution string. And the RewriteRule pattern ^$ is the same as ^/?$ when used in .htaccess.

Assuming you are on Apache and you are internally rewriting the request to the WordPress front-controller (the standard WP .htaccess directives) then you need to check REDIRECT_NOINDEX in the Header directive, despite setting the NOINDEX env var in the preceding RewriteRule directive. (The rewrite engine triggers a "loop" and the NOINDEX env var is renamed to REDIRECT_NOINDEX.)

You'll need to clear your browser cache before testing and preferably test first with 302 (temporary) redirects before making it a 301 (permanent) redirect.

  • 1
    Than you for this! I was able to achieve what I needed using this information. :) Commented May 25, 2021 at 10:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.