I have a situation where I want to take the following URL:
/1/john
and have it redirect using Apache's htaccess file to go to
/page.php?id=1&name=john#john
so that it goes to an html anchor with the name of john.
I've found a lot of reference to escaping special characters, and to adding the [NE] flag so that the redirect ignores the # sign, but these don't work. For example, adding [NE,R] means that the URL just appears in the browser address as the original: http://example.com/page.php?id=1&name=john#john.
This is possible using [NE] flag (noescape).
By default, special characters, such as & and ?, for example, will be converted to their hexcode equivalent. Using the [NE] flag prevents that from happening.
More info http://httpd.apache.org/docs/2.2/rewrite/flags.html#flag_ne
You can in fact do one of these things, but not both.
You can use the [NE] flag to signify to Apache not to escape the '#' character, but for the redirect to work, you have to specify an absolute URL to redirect to, not simply a relative page. Apache cannot do the scrolling of the window down to the anchor for you. But the browser will, if you redirect to an absolute URL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With