Search code examples
angularjsapache.htaccess

htaccess hash url redirection to without hash issue with hyphens


I'm facing url (hash) redirecting issue in my angular application. I tried fixing it with angular way but it doesn't work so I go with custom .htaccess way. This solution is working fine but I'm facing issue with (duplicate) URL(s) which have hyphen(s). Example below.

.htaccess

RewriteEngine On
RedirectMatch 301 ^/terms    http://example.com/#terms
RedirectMatch 301 ^/terms-bb http://example.com/#terms-bb

As per above example if open "http://example.com/terms-bb" it redirects to "/terms" instead. So is there any way that I can strictly match these duplicate urls?


Solution

  • You only anchored your patterns at the start there, so ^/terms matches on anything that starts with /terms.

    If you want a strict match, then anchor it at the end as well – ^/terms$.