Redirect to anchor

Viewed 55

I need to redirect an url like this domain.tld/instagram/anchor to domain.tld/instagram/#anchor.

This should only happen on links with the instagram path and must be handled via .htaccess, I tried this and I'm now stuck because this does nothing:

RewriteRule ^/instagram/(\d[^/]+) /instagram/#$1/ [R=301,NE,L]
1 Answers

With your shown samples, please try following rules. Please make sure to clear your browser cache before testing your URLs.

RewriteEngine ON
RewriteRule ^instagram/([^/]*)/?$ /instagram/#$1/ [R=301,NC,NE,L]

Important points:

  • Always use NE and NC flags to your rules to make sure conditions are well formed.
  • You need not to use \d here in your regex since you are not having digits in your shown samples.
  • You need to make sure to keep this Rules at top because of redirection it should come first, in case later we have other rules related to it.
  • You need not to match / in starting here.
Related