Articles of add rewrite rule

add_rewrite_rule issues

i usually add rewrite rules for custom pages like this: add_rewrite_rule(‘^deal-purchase?’,’index.php?is_purchase_page=1&post_type=page’,’top’); However on a site im working on now, the above just redirects to the home page whereas if i create a custom post type and reference that: add_rewrite_rule(‘^deal-purchase?’,’index.php?is_purchase_page=1&post_type=market’,’top’); it works. Anyone any ideas what might be causing the 1st code to fail?

Remove rewrite endpoint on deactivation?

I’m using Milo’s answer to add a Rewrite Endpoint as part of my plugin. Is there a straight-forward way to remove a Rewrite Rule upon deactivation? I found this snippet but I’d expect a “remove_rewrite_endpoint” to match add_rewrite_endpoint Also, how do I know what to look for in the rewrite rules list when add_rewrite_endpoint was […]

WP redirect rule doesn't work

I’m trying to redirect the page http://www.example.org/newsletter/unsubscribe.html to http://www.example.org/newsletter/unsubscribe. I have tried the following: add_rewrite_rule(‘newsletter/unsubscribe.html$’, ‘newsletter/unsubscribe’, ‘top’); If I var_dump the global wp_rewrite i see the following rule added: … public ‘non_wp_rules’ => array (size=1) ‘newsletter/unsubscribe.html$’ => string ‘newsletter/unsubscribe’ (length=20) … Does anyone know what I am missing?

Do rewrites added with add_rewrite_rule() persist after plugin deletion?

I am developing a WordPress plugin and need to ad a rewrite url using add_rewrite_rule(). That does work. But what happens when my plugin is deleted? Does WordPress cleanup the htaccess or do I need to do that? How can I remove a url which was added using add_rewrite_rule()?

Using category slug in add_rewrite rule

I’m using this function ro rewrite URLs: function archive_rewrite_rules(){ add_rewrite_rule( ‘inspiracao/([^/]*)/([0-9]{4})/?$’, ‘index.php?post_type=post&cat=$matches[1]&year=$matches[2]’, ‘top’ ); } add_action( ‘init’, ‘archive_rewrite_rules’ ); But is possible to use category slug instead category id?

configuration of .htaccess for add_rewrite_rule to make sense

I am trying this code from codex wordpress site function custom_rewrite_basic() { add_rewrite_rule(‘^leaf/([0-9]+)/?’, ‘index.php?page_id=$matches[1]’, ‘top’); } add_action(‘init’, ‘custom_rewrite_basic’); How must by .htaccess file must be configured for above code to make sense? If I put the basic wordpress .htaccess configuration file then I get redirected to same page. <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule […]

How to change the displayed URL?

I’d like URLs like this: http://example.com/root/branch/twig/ be rewritten and displayed to a URL like the one below: http://example.com/root/twig/ At the moment, the two URLs point to the same resource so there is no difference between them on the site apart from how they look like. I’d like wordpress to display the shorter version. How can […]

Rewriting in wordpress url

Yes we love to make the url more shorter ,more clean. Lets say we have css url like this xxx.com/wp-content/theme_name/css/my_custom_css.css However i would love to display it like this xxx.com/css/my_custom_css.css So i think rewriting is best choice. I created a plugin made a new file rewrite.php and included the file and inserted code in rewrite.php […]

Rewrite Rule for Custom Page with Query Vars in URL

Background I have a a page called ‘listen’ with a custom template, which runs a custom wp_query that uses the ‘show’ variable in the URL. The following example works… example.com/listen/?show=thebigshow What I Want I want to be able to get rid of the ?show= part of the url, and format it as follows… example.com/listen/thebigshow What […]

Rewrite rules for short URL

Requirement I have implemented Document Short URL to allow people to access PDF documents on the servers using their unique IDs, without knowing their full paths. Documents are PDF files, so they should be opened inline browser. This works so that is not the problem. For example http://www.example.com/INV0001-00-001 Where INV0001-00-001 is the Unique ID My […]