0

I need to redirect all traffic with an URL including "#" character and replace the character by XYZ.

For example, a request to

http://www.example.com/page.php?var=test#1

needs to be redirected to

http://www.example.com/page.php?var=test#XYZ

the # can be anywhere in the URL query

Is it possible to do it with an htaccess ? AFAIK it won't work with PHP because anything next to # is ignored by the script (unless you have something to suggest me)

Anar Choi
  • 201
  • 2
  • 3
  • 9

1 Answers1

1

Is it possible to do it with an htaccess

No. The # and everything after it is a URL fragment. It's never sent to the server, thus there's no way the webserver, or mod_rewrite (or, like you said, a script like php) even knows it's there.

You're going to have to do something that's strictly on the client's end in order to change a fragment (e.g. using javascript). The htaccess file can't help you at all.

For example, see the answer to this question: Remove fragment in URL with JavaScript w/out causing page reload

Community
  • 1
  • 1
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • I tried the script in this link, it will remove the anchor and everything next to it. But i just want to replace # by XYZ and keep everything after the character – Anar Choi Jul 04 '13 at 03:27