10

I know you can't redirect anchor URLs to another page, but is it possible to redirect a URL to only a single anchor?

So

http://www.example.com/video/{title}

always gets sent to

http://www.example.com/video.php?title={title}#player

The only thing that changes is the title, anchor is always the same. I need to redirect to a certain slide on a coda slider

Amit Verma
  • 40,709
  • 21
  • 93
  • 115
Graham
  • 323
  • 1
  • 4
  • 8

2 Answers2

22
RewriteRule ^/video/(.*) /video.php?title=$1#player [NE,L,R=301]

NE|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.

Source : http://httpd.apache.org/docs/current/en/rewrite/flags.html

Community
  • 1
  • 1
Paul Groves
  • 3,983
  • 2
  • 23
  • 24
  • NE-Flag is unknown for ```Apache/2.4.6```. ```httpd -V``` logs the following: ```RewriteCond: unknown flag 'NE'``` – SWiggels Jan 29 '21 at 10:12
9

You should be able to use the # sign in a redirect rule if you specify the NE flag (No Escape)

Dan Andreatta
  • 3,611
  • 1
  • 22
  • 15
  • 1
    Thanks Dan, it seems to need the 301 redirect too – Graham Apr 21 '10 at 20:22
  • 1
    I didn't need the 301, but if you are using a permanent redirect, hitting refresh in your browser will likely use the cached (escaped) redirect rule. Clear your cache or try with another browser. – Mark McDonald Aug 23 '12 at 03:26