WordPress rewrite does not work for some reason

I am new to WordPress rewrites, so after some StackExchange reading i have figured it out. All rewrites should be passed to index.php, then i can call the page that i want to redirect to, like this: function custom_rewrite_basic() { add_rewrite_rule( ‘validate_data.php’, ‘index.php?pagename=validate-data’, ‘top’ ); } add_action( ‘init’, ‘custom_rewrite_basic’ ); In addition i wanted to … Read more

Rewrite rule and display of post

I don’t understand why but the regex seemed to be the last issue. It was catching it but even with the post name hardcoded in it didn’t work correctly. This is the final working version. add_filter( ‘post_link’, ‘custom_permalink’, 10, 3 ); add_filter(‘rewrite_rules_array’,’wp_insertMyRewriteRules’); add_filter(‘init’,’flushRules’); function custom_permalink( $permalink, $post, $leavename ) { $category = get_the_category($post->ID); if ( … Read more

Permalink sub-routing catch-all

You can add an internal rewrite so WordPress recognizes these requests. In the same function hooked to init where you add the post type, you can add: add_rewrite_tag( ‘%tutorial_fragment%’, ‘([^/]+)’ ); add_rewrite_rule( ‘tutorial/([^/]+)/([^/]+)/?$’, ‘index.php?tutorial=$matches[1]&tutorial_fragment=$matches[2]’, ‘top’ ); The value is available via the WP API after the request is parsed: $value = get_query_var( ‘tutorial_fragment’ ); After … Read more

Redirect, Change URLs or Redirect HTTP to HTTPS in Apache – Everything You Ever Wanted to Know About mod_rewrite Rules but Were Afraid to Ask

mod_rewrite syntax order mod_rewrite has some specific ordering rules that affect processing. Before anything gets done, the RewriteEngine On directive needs to be given as this turns on mod_rewrite processing. This should be before any other rewrite directives. RewriteCond preceding RewriteRule makes that ONE rule subject to the conditional. Any following RewriteRules will be processed … Read more

How can I create custom URL routes?

Add this to your theme’s functions.php, or put it in a plugin. add_action( ‘init’, ‘wpse26388_rewrites_init’ ); function wpse26388_rewrites_init(){ add_rewrite_rule( ‘properties/([0-9]+)/?$’, ‘index.php?pagename=properties&property_id=$matches[1]’, ‘top’ ); } add_filter( ‘query_vars’, ‘wpse26388_query_vars’ ); function wpse26388_query_vars( $query_vars ){ $query_vars[] = ‘property_id’; return $query_vars; } This adds a rewrite rule which directs requests to /properties/ with any combination of numbers following to … Read more

flush_rewrite_rules() not working with update_option_{$option}

flush_rewrite_rules() should be called very early within the WordPress initialization. The reason is that the entpoints cannot be changed afterwards. A solution could look like this: function updateMySlugOption($old_value, $value, $option) { if( $old_value != $value ) { set_transient(‘update_slugs’, 1); } } add_action( ‘update_option_mySlug’, ‘updateMySlugOption’, 10, 3); function update_slugs() { if( get_transient(‘update_slugs’) ) { flush_rewrite_rules(); delete_transient(‘update_slugs’); … Read more

WordPress and Htaccess

‘RewriteBase /’ is not needed. RewriteBase allows you to change your internal directory structure to something other than what a browser sees. IE: If all your files are in ‘http://mydomain.com/site’, but you wanted ‘http://mydomain.com’ to be the path browsers see, you would use a RewriteBase /site and apache’s mod_rewrite would happily add that substitution for … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)