Issues with RewriteRule on Generic Anchor Redirect

Refresh

April 2019

Views

35 time

1

I want to redirect any request to the root of my site to an anchor on the index. So

https://example.com/foo

Gets sent to

https://example.com/#foo

I've written this .htaccess file (it also redirects http requests to https, that part works, but is included for completeness)

RewriteEngine On
RewriteRule ^/(.*) /#$1 [NE,R=302]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Based on the discussion in this thread: mod_rewrite with anchor link this should work, but it's not matching for some reason. I tried out the rule given in that thread using this tool: http://htaccess.madewithlove.be/ and it doesn't seem to work there either.

I've tried clearing my cache and accessing in incognito mode, to no avail. Any help?

0 answers