4

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
4

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.

  • Nice! I did not have my thinking cap on. ;-) Typical these days. Cheers!! – closetnoc Jun 12 '18 at 1:53
  • 1
    Thanks! I think I found clarification to my initial question here: stackoverflow.com/questions/29994275/… The issue was due to the UTM parameter. As I understand it now, the anchor should go after the UTM parameter. That was the problem. And now it kinda does make sense. Thanks! – mvsainz Jun 12 '18 at 2:02
  • @mvsainz Ah, yes. The anchor has to be the last parameter... Protocol, domain, path, query strings, anchor. The order is important (Except among the query strings, but even then, you could support a specific query string order because it is valid to send two parameters with the same name.) – Alexis Wilke Jun 12 '18 at 2:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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