Arif Sami
Arif Sami

Reputation: 317

.htaccess redirect url and remove #591 from resulting url

I've a backlink of my website as

http://localhost/babycare/article/detail/93#591

I want to redirect it to a new user-friendly url like

http://localhost/babycare/article/detail/feeding_aversion

The code i've written in my .htaccess file is here

RewriteCond %{THE_REQUEST} /article/detail/93 [NC] 
RewriteRule ^/?(babycare)? /article/detail/Feeding_Aversion? [R=301]

But it redirects to

http://localhost/babycare/article/detail/feeding_aversion#591

How could i remove #591 from url.

Upvotes: 0

Views: 39

Answers (1)

Tom
Tom

Reputation: 4292

The problem you've got is that location hashes usually only exist in the browser, and are not meant to be handled by the server.

Its covering in more detail in the following answers;

URL Fragment and 302 redirects

Which one is better pushstate or location.hash?


You could use Javascript to remove the hash's if they're that much of an issue.

location.hash = "";

Should achieve what you're looking for - obviously it'll need to go onto each page.

Upvotes: 1

Related Questions