I want to rewrite http://example.com/articles.html#first-article
with http://example.com/articles/first-article
Is it possible to rewrite?
I tried using following but didn't work for me:
RewriteRule ^articles/(.+)$ /articles\.html\#$1
Use a 301 redirect . htaccess to point an entire site to a different URL on a permanent basis. This is the most common type of redirect and is useful in most situations. In this example, we are redirecting to the "example.com" domain.
htaccess rewrite rules can be used to direct requests for one subdirectory to a different location, such as an alternative subdirectory or even the domain root. In this example, requests to http://mydomain.com/folder1/ will be automatically redirected to http://mydomain.com/folder2/.
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.
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