codieboie
codieboie

Reputation: 52

rewrite url using htaccess or hide some text from url

 The url showing in the address bar: www.testsite.com/news#tab-1
 The url which I want to show: www.testsite.com/news
 The url showing in the address bar: www.testsite.com/news#tab-2
 The url which I want to show: www.testsite.com/events

I tried rewriting rule using htaccess

 RewriteCond %{REQUEST_URI} /news#tab-2$
 RewriteRule .* /news[L]

and

 RewriteRule www.testsite.com/test www.testsite.com/news#tab-1

But it didnt work. Please help.

Upvotes: 0

Views: 444

Answers (2)

Daniel Ferradal
Daniel Ferradal

Reputation: 2900

Client browsers do not send the character "#" to the server. If you have access to the server Logs you will see all the server gets is "GET /news" and omits the rest. "#" is a client side interpreted character.

You will have to hex encode it in the url if you insist on sending it to the server, but it is probably better if you use a more common URI path or even query string "?" if you want to do internal redirections from the server.

As a friendly side-note. Do not use .htaccess unless you are not the admin of the Apache HTTPD server. It is not necessary to redirect/rewrite as it complicates them and it produces bigger overhead to the server since the file needs to be constantly checked for changes.

Upvotes: 0

sietse85
sietse85

Reputation: 1506

You can't rewrite Anchors with .htaccess. You need to use something client side, like javascript in order todo so.

This article i found in another similiar question you can read it here: Remove fragment in URL with JavaScript w/out causing page reload

Upvotes: 2

Related Questions