I want to rewrite http://example.com/articles.html#first-article with http://example.com/articles/first-article
Is it possible to rewrite?<
The # can be added in the substitution URL with the NE flag. Check:
This Apache link that describes specifically how to redirect anchors.
This W3C Protocols link and this one.
This answer in SO is pretty complete.
Another answer in SO.
Another answer in SO (mine).
So, you may try this:
Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !articles\.html [NC]
RewriteCond %{REQUEST_URI} ^/articles/([^/]+)/? [NC]
RewriteRule .* /articles.html#%1 [R,NE,L]
Redirects
http://example.com/articles/parameter
To
http://example.com/articles.html#parameter
String articles is assumed to be fixed while parameter is assumed to be variable.
No, it's not possible. The URL fragment (everything from # on) not even gets sent to the server.
Maybe you want to consider a JavaScript based solution, where the actual content will be loaded via AJAX dependent on the fragment. You will find some useful information about this method here: What's the shebang/hashbang (#!) in Facebook and new Twitter URLs for?