Subhashree Panda
Subhashree Panda

Reputation: 23

Removing a string from url in php

How to remove a specific string from URL in .htaccess file.

For example my root URL is www.example.com. If someone puts www.example.com/# , it should redirect to root URL.

I have tried with

RewriteEngine on 
RewriteBase / 
RewriteRule ^#/(.*) /$1 [R=302,L]

Upvotes: 0

Views: 38

Answers (1)

Provie9
Provie9

Reputation: 379

The hash in the URL isn`t sent to the server when requesting a page, so you can't use redirect rules like that. It's client-side only.

You can change the url only with javascript:

if (location.href.indexOf("#") > -1) {
    location.assign(location.href.replace(/\/?#/, ""));
}

Upvotes: 1

Related Questions