简体   繁体   中英

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]

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(/\/?#/, ""));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM