我在wordpress網址中遇到問題。下面我有WordPress在網址中添加數字
但在搜索引擎
http://www.example.com/sample-post/
http://www.example.com/sample-post/500012
網址
請給我一個想法來解決這個問題。
我在wordpress網址中遇到問題。下面我有WordPress在網址中添加數字
但在搜索引擎
http://www.example.com/sample-post/
http://www.example.com/sample-post/500012
網址
請給我一個想法來解決這個問題。
我對
https://wordpress.stackexchange.com/questions/70992/appending-numbers-to-url-do-not-break-the-link
http://toscho.de/2010/wordpress-plugin-canonical-permalink/ 說明找到了答案:刪除請求URI非法數字後綴。 版本:0.3作者:Thomas肖爾茨作者URI:http://toscho.de 創建:2010年4月4日 */
ADD_ACTION( 'WP', 't5_canonical_request');/** * WordPress允許具有任何數字後綴的URI ,例如:*/canonical-page-or-postname/12345/ *此功能執行簡單的檢查並在必要時將規則URI重定向到*。 * * @return void */function t5_canonical_request(){ global $ page,$ post;
// post, page, attachment, preview if (! is_singular() or is_preview()) { return; } $permalink = get_permalink(); // We don't have access to the number of sub pages here. // So we have to hack. $max_pages = substr_count( $post->post_content, '<!--nextpage-->') + 1; if (1 < $page and $page <= $max_pages) { /* * Handle different permalink settings, eg: * /%year%/%postname%.html or * /%year%/%postname%/ */ $rev_perma_struct = strrev(get_option('permalink_structure')); if ('/' != $rev_perma_struct[0]) { $permalink .= "/$page"; } else { $permalink .= "$page/"; } } $host_uri = 'http' . (empty ($_SERVER['HTTPS']) ? '' : 's') . '://' . $_SERVER['HTTP_HOST']; $canonical_path = str_replace($host_uri, '', $permalink); if (! empty ($_GET)) { global $wp; // Array $allowed = $wp->public_query_vars; $out_arr = array(); foreach ($_GET as $k => $v) { if (in_array($k, $allowed)) { $out_arr[] = $k . (empty ($v) ? '' : "=$v"); } } if (! empty ($out_arr)) { $canonical_path .= '?' . implode('&', $out_arr); } } if ($canonical_path == $_SERVER['REQUEST_URI']) { return; } // Debug current result: #print '<pre>' . var_export($canonical_path, TRUE) . '</pre>'; // Change it or return 'false' to stop the redirect. $canonical_path = apply_filters( 't5_canonical_path', $canonical_path ); if (FALSE != $canonical_path) { header('Location: ' . $permalink, true, 301); die("<a href='$permalink'>$permalink</a>"); } return; }
因爲你使用了相同的slu??或檢查網址模板表單設置 – Abudayah
我不明白你的觀點我有/%postname%/永久鏈接 –