Support » Plugins » Hacks » Custom url rewrites needed

  • I have a custom search on an external products database which I output results to a WP Page using a custom template file. I need to use a specific seo url structure for this page…

    – Currently the Page’s url is ‘/equipment’

    What I would like to do is use ‘/equipment/search’ for the search results and ‘equipment/{manufacturer_name}/{part_number}’ for the individual product details page, preferably using the same template file.

    I have added a couple of custom URL params in ‘functions.php’ using the following:

    function custom_query_vars( $vars ) {
    	$vars[] = ' load'; // Page type (i.e. Search or Details)
    	$vars[] = ' mfr'; // Manufacturer
    	$vars[] = ' prt'; // Part
    	return $vars;
    add_filter('query_vars', 'custom_query_vars' );

    I also have another code snippet which I have been trying to adapt:

    function add_rewrite_rules($wp_rewrite) {
    	$wp_rewrite->rules = array(
    		'equipment/(?:\?load=(.+))' => 'index.php?page_id=227&load='.$wp_rewrite->preg_index(1)
    	) + $wp_rewrite->rules;
    add_action('generate_rewrite_rules', 'add_rewrite_rules');

    I have also tried adding the Rewrite Rules directly into the htaccess file, outside of the WP block, but neither method seems to work.

    Please, there must be an easy way to add my own URL rules to wordpress?!

Viewing 1 replies (of 1 total)
  • chucklin72


    You can write a simple plugin and custom route the URL. Basically the idea is to hook into wordpress’s hierarchy and instead of it returning “page not found”, intercept and use the URL as you wish.

    I ran into this problem as well and I wrote a document on how to do this.
    Custom Routing

Viewing 1 replies (of 1 total)
  • The topic ‘Custom url rewrites needed’ is closed to new replies.