我想重寫http://website.com/?slug=product_info.php&products_id=32
到http://website.com/product_info/32
,我使用此代碼,WordPress的重寫URL
add_filter('rewrite_rules_array','wp_insertMyRewriteRules');
add_filter('query_vars','wp_insertMyRewriteQueryVars');
// Adding a new rule
function wp_insertMyRewriteRules($rules)
{
$newrules = array();
$newrules['(product_info)/(\d*)$'] = 'index.php?pagename=store&slug=product_info.php&products_id=$matches[1]';
return $newrules + $rules;
}
// Adding the bid var so that WP recognizes it
function wp_insertMyRewriteQueryVars($vars)
{
array_push($vars, 'products_id');
return $vars;
}
我也用這個代碼,
add_action('init', 'wpse41778_add_rewrite');
function wpse41778_add_rewrite()
{
add_rewrite_tag('%products_id%','([^/]+)');
add_rewrite_tag('%slug%','([^/]+)');
add_rewrite_rule(
'^product_info/([^/]+)/?$',
'index.php?pagename=store&slug=product_info.php&products_id=$matches[1]',
'top'
);
}
我已經手動刷新的規則,但是當我去到http://website.com/product_info/32
它去http://website.com
,而不是產品頁面。這兩個代碼都有這種問題。
這裏是我的.htaccess的內容,
# BEGIN WordPress
RewriteEngine On
RewriteBase/
RewriteRule ^index\.php$ - [L]
# uploaded files
RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]
RewriteRule ^login$ /wp-login.php [L]
RewriteRule ^signup$ /wp-signup.php [L]
RewriteRule ^register$ /wp-register.php [L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule^- [L]
RewriteRule . index.php [L]
我不知道什麼這個問題,我其實新手。請幫忙。
我不認爲這會爲您解決問題但你應該在你的重寫規則 – 2012-03-31 08:06:33
中使用'products_id = $ matches [2]',但仍然沒有成功。如果我的代碼無法正常工作,你能否提出另一種解決方案? – Ken 2012-03-31 08:12:11
「商店」頁面是否存在? – 2012-03-31 08:18:34