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:


be redirected to:



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:


1 Answer 1



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
    Commented Jun 12, 2018 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
    Commented Jun 12, 2018 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.) Commented Jun 12, 2018 at 2:32

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.