I had to setup a redirect the other day with a hashtag. Whenever a visitor hit a specific URL, I wanted to redirect them to another URL but I also wanted to include a hashtag to indicate where they came from when tracking the information in Google Analytics.
It appears the secret is the NE flag otherwise the #
gets escaped as %23
.
Example of htaccess rule to Redirect with Hashtag
RewriteRule ^(?i:redirectme)$ http://example.com/common/#from-redirectme [NE,R=301,L]
http://example.com/redirectme
redirects to
http://example.com/common/#from-redirectme
photo credit: much0 via photopin cc
Thanks for the rewrite. What I’m looking for is a rewrite for a hashtag that has been moved:
https:/www.mydomain.com/#/!/xyz.html to https://www.mydomain.com/#!/xyz
There are two changes:
/#/! has been replaced by /#!
and the html of the hash has been removed.
Thx for your feedback.
Hi Frank,
Unfortunately, you can not use an htaccess redirect based on the value after the `#`.
The hashtag and anything after it are not sent to the server.
You can read more about this here, http://stackoverflow.com/questions/8185188/redirect-url-with-hash-using-htaccess-file
Thanks Sal, this is what I was looking for and helped me solve a problem!