簡體   English   中英

從PHP中的URL中刪除字符串

[英]Removing a string from url in php

如何從.htaccess文件中的URL中刪除特定的字符串。

例如,我的根URL是www.example.com 如果有人輸入www.example.com/# ,則應重定向到根URL。

我嘗試過

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

請求頁面時,URL中的哈希不會發送到服務器,因此您不能使用這樣的重定向規則。 僅在客戶端。

您只能使用javascript更改網址:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM