admin管理员组文章数量:1291594
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!
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!
Share Improve this question edited May 25, 2021 at 8:54 Jorge Consiglio asked May 25, 2021 at 8:25 Jorge ConsiglioJorge Consiglio 134 bronze badges 1- What directives are you "inheriting"? – MrWhite Commented May 25, 2021 at 9:53
1 Answer
Reset to default 0A 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.
本文标签: Redirect homepage with htaccessexcept if I enter the link adding quothomequot
版权声明:本文标题:Redirect homepage with htaccess, except if I enter the link adding "home" 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741538236a2384159.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论