2015-06-22 76 views
0

我從導航通過使用PHP頭重定向到不保留哈希值

if($course_id != $_GET['id']) { 
    header("location: /courses/"); 
} 

但是具有類似

http://solo.dev/module-1/behavioural-safety/?id=7#14 

一個URL的網頁了,它仍然存在#14的值

http://solo.dev/courses/#14 

如何在不保留散列值的情況下重定向到僅僅/courses/

回答

0

試試這將工作 那樣簡單,

header('location: /courses#'); 

空哈希你可以做到這一點,

window.location.hash = ''; 
window.location.href = "http://yoururl.com" 
+0

我不想哈希值,即使是空的哈希,最好我的網址是http://solo.dev/courses/而不是http://solo.dev/courses/# –

+0

訪問此問題http://stackoverflow.com/questions/7338853/php-location-header-ignore-hash –

0

您可以指定空哈希代替:

header("location: /courses/#"); 

然後,在您檢查網站,如果有一個空的哈希值,並使用刪除的JavaScript:

history.pushState('', document.title, window.location.pathname);