Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'hash' url rewrite in .htaccess

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
like image 636
blue ghhgdtt Avatar asked Feb 28 '13 10:02

blue ghhgdtt


People also ask

How can I redirect and rewrite my urls with an .htaccess file?

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.

What is rewrite rule in htaccess?

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/.


1 Answers

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.

like image 179
Felipe Alameda A Avatar answered Sep 29 '22 16:09

Felipe Alameda A