I want to redirect all incoming requests to another url if it doesn't contain # and admin. I need it for angular.js, but I have /admin with php
For example:
http://example.com/link-to-article -> http://example.com/#/link-to-article
http://example.com/admin/* will not redirect
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.!
negates whole match in RewriteRule
pattern((admin|login)(/.*)?)?
matches anything that is /admin/
or /login/
OR emptry (landing page)/#%{REQUEST_URI}
where %{REQUEST_URI}
represents original URI.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