Skip to main content
fixed »url url« in title
Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459

Help with Wordpress custom url url rewriting?

edited tags
Link
Jan Fabry
  • 30.5k
  • 4
  • 90
  • 136
added 187 characters in body
Source Link
user1147
  • 802
  • 4
  • 14
  • 26

I have 3 problems. First,I would like something like this to do :

www.example.com/myblog => myblog.example.com

myblog is template page. and then when open one post from that page(post are custom post type) url will look like this myblog.example.com/my-custom-post-type-post

Second :

www.example.com/mycar => mycar.example.com

my car is also template page,and then when open post from that page(posta are also custom post type,but this time post will be in subcategory) url will look something like this

mycar.example.com/my-subcategory/my-car-custom-post-type

Dont know how to do this in wp.

Third,can someone help me to figure it out why is this not working. I would like to rewrite this url http://www.example.com/data-page/?data_id=123456789 to http://www.example.com/data-page/data_id/123456789

add_filter('query_vars', 'add_my_var');

function add_my_var($public_query_vars) {
    $public_query_vars[] = 'data_id';
    return $public_query_vars;
}

function add_rewrite_rules($rules) {
    $newrules['data-page/?data_id/([0-9]{1,})/?$'] = 'index.php?data_id=$matches[1]';
    $rules = $newrules + $rules;
    return $rules;
}

function flushRules() {
    global $wp_rewrite;
    $wp_rewrite->flush_rules();
}

add_filter('rewrite_rules_array', 'add_rewrite_rules');
add_filter('init', 'flushRules');

This is the way I send data to another page.

<a href="<?= add_query_arg(array('data_id'=>32),get_permalink(get_page_by_path('data-page'))); ?>">Data page test link</a>

Thanx in advance.

I have 3 problems. First,I would like something like this to do :

www.example.com/myblog => myblog.example.com

myblog is template page. and then when open one post from that page(post are custom post type) url will look like this myblog.example.com/my-custom-post-type-post

Second :

www.example.com/mycar => mycar.example.com

my car is also template page,and then when open post from that page(posta are also custom post type,but this time post will be in subcategory) url will look something like this

mycar.example.com/my-subcategory/my-car-custom-post-type

Dont know how to do this in wp.

Third,can someone help me to figure it out why is this not working. I would like to rewrite this url http://www.example.com/data-page/?data_id=123456789 to http://www.example.com/data-page/data_id/123456789

add_filter('query_vars', 'add_my_var');

function add_my_var($public_query_vars) {
    $public_query_vars[] = 'data_id';
    return $public_query_vars;
}

function add_rewrite_rules($rules) {
    $newrules['data-page/?([0-9]{1,})/?$'] = 'index.php?data_id=$matches[1]';
    $rules = $newrules + $rules;
    return $rules;
}

function flushRules() {
    global $wp_rewrite;
    $wp_rewrite->flush_rules();
}

add_filter('rewrite_rules_array', 'add_rewrite_rules');
add_filter('init', 'flushRules');

Thanx in advance.

I have 3 problems. First,I would like something like this to do :

www.example.com/myblog => myblog.example.com

myblog is template page. and then when open one post from that page(post are custom post type) url will look like this myblog.example.com/my-custom-post-type-post

Second :

www.example.com/mycar => mycar.example.com

my car is also template page,and then when open post from that page(posta are also custom post type,but this time post will be in subcategory) url will look something like this

mycar.example.com/my-subcategory/my-car-custom-post-type

Dont know how to do this in wp.

Third,can someone help me to figure it out why is this not working. I would like to rewrite this url http://www.example.com/data-page/?data_id=123456789 to http://www.example.com/data-page/data_id/123456789

add_filter('query_vars', 'add_my_var');

function add_my_var($public_query_vars) {
    $public_query_vars[] = 'data_id';
    return $public_query_vars;
}

function add_rewrite_rules($rules) {
    $newrules['data-page/data_id/([0-9]{1,})/?$'] = 'index.php?data_id=$matches[1]';
    $rules = $newrules + $rules;
    return $rules;
}

function flushRules() {
    global $wp_rewrite;
    $wp_rewrite->flush_rules();
}

add_filter('rewrite_rules_array', 'add_rewrite_rules');
add_filter('init', 'flushRules');

This is the way I send data to another page.

<a href="<?= add_query_arg(array('data_id'=>32),get_permalink(get_page_by_path('data-page'))); ?>">Data page test link</a>

Thanx in advance.

Source Link
user1147
  • 802
  • 4
  • 14
  • 26
Loading