WordPress.org

Ready to get started?Download WordPress

Forums

Help with add_rewrite_rule() (6 posts)

  1. chibib0
    Member
    Posted 2 years ago #

    I have difficult in using add_rewrite_rule(). Please help me rewrite this query string url.

    I want to change the following using add_rewrite_rule(),
    http://website.com/?slug=product_info.php&products_id=32 to http://website.com/products/32.

    http://website.com/?slug=register.php to
    http://website.com/register

    http://website.com/?slug=index.php&cPath=1 to
    http://website.com/category/1

    Thank you.

  2. I think you're unclear about the direction...

    If you wanted those in the reverse order such as

    http://website.com/products/32 to http://website.com/?slug=product_info.php&products_id=32

    http://website.com/register to http://website.com/?slug=register.php

    http://website.com/category/1 to http://website.com/?slug=index.php&cPath=1

    Then it ought to be add_rewrite_rule() (which I couldn't get working either).

    If you want to go the direction you say, them try template_redirect().

    http://pastebin.com/RrrzMH8d

  3. chibib0
    Member
    Posted 2 years ago #

  4. Well sure it's not working. There are no add_rewrite_rule() in place to handle the new URLs. ;D

    I'll take a look tonight, perhaps someone else can suggest a solution. When I tried the add_rewrite_rule() it complained about missing something so I was certainly using the function incorrectly.

  5. Tekime
    Member
    Posted 2 years ago #

    For custom plugins where you're taking over the interface, I've had so many issues with the built-in rewrites I just baked my own:

    http://gabrielharper.com/blog/2012/09/wordpress-custom-urls-for-plugins/

    I don't know if this is any help but it's SO much simpler. Would love to hear about any improvements or potential problems using this method....

  6. chibib0
    Member
    Posted 2 years ago #

    @Tekime

    Thank you! I guess this is the solution ive been looking for however, im still a php newbie.. Can you please provide me an example using my scenario?

    Like, making http://website.com/?slug=product_info.php&products_id=32 to http://website.com/products/32

    The plugin's template for ?slug=product_info.php is /wp-content/plugins/myplugin/product_info.php

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags