问题原文
原帖链接 · mvsainz · CC BY-SA 4.0
I believe this can't be done, but it would be good to confirm either way. To know if it's worth investing more time in or not.
Can a .htaccess file rewrite/redirect:
example.net/postname#heading2
be redirected to:
example.com/postname#heading2
?
I'm starting to assume that the server does not see anything past the #. I am also trying to add a UTM parameter after #heading2 in the process. The current rewrite is adding #heading2 appended directly after the UTM paramter.
Any confirmation would be appreciated.
EDIT: Apparently I was understanding the issue wrong due to the combination of anchors with UTM parameters. The URL was properly redirecting via .htaccess, it's just that I was unaware that the #anchor should always go at the end of the URL, even if there's a UTM parameter before it. Reference.
Therefore the right URL was always supposed to look like:
example.com/postname/?utm_source=XYZ#heading2
已采纳解答
原帖链接 · Alexis Wilke · CC BY-SA 4.0
No.
The anchor is a browser side only parameter which is not sent to the server.
You either need to transform the #anchor into a query string or a path, or have some JavaScript that understands how to handle that special case.
If you know of the specific anchor, having a specific URL that understands about it would work. But that's similar to placing that parameter in a query string or as part of the path.
Twitter used the anchor capability quite a bit, but all their code used JavaScript to retrieve the data to be displayed. That's why that worked well for them.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
