You can use this code in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^((admin|login)(/.*)?)?$ /#%{REQUEST_URI} [L,NC,NE,R=302]
Also remember that web server doesn't URL part after #
as that is resolved only on client side.
RewriteCond %{REQUEST_FILENAME} !-f
skips this rule for all files.
- Using
!
negates whole match in RewriteRule
pattern
((admin|login)(/.*)?)?
matches anything that is /admin/
or /login/
OR emptry (landing page)
- If negation is true then this rule redirects it to
/#%{REQUEST_URI}
where %{REQUEST_URI}
represents original URI.
References: