add_rewrite_rule confusion

Expanding on my comment: The Rewriting API is for rewriting URLs, not redirecting. So the URL won’t change. You’re just telling WordPress that /testpage/ should load page_id 81, but the URL will stay /testpage/. Regardless, I tried the below, (where 501 is an ID that exists on my install) and it worked fine, loading that … Read more

I need a custom permalink for my website

I’m not sure if I should assume that you were issuing your examples inside of the init hook, but if not that is the reason they weren’t working for you. So inside functions.php function sd_rewrite_rules() { add_rewrite_tag(‘%domain_name%’, ‘([^&]+)’); add_rewrite_rule(‘^/([^/]*)/?’,’index.php?domain_name=$matches[1]’,’top’); } add_action(‘init’, ‘sd_rewrite_rules’, 10, 0); Then if you wanted to retrieve the query variable to do … Read more

Rewrite rule to load images from production does nothing

RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php [L] # If images not found on development site, load from production RewriteCond %{REQUEST_URI} ^/wp-content/uploads/[^\/]*/.*$ RewriteRule ^(.*)$ https://www.example.com/$1 [QSA,L] The problem here is that “If images not found on development site” then the request has already been rewritten to index.php by the preceding RewriteRule (WordPress front-controller), … Read more

Where do I USE add_rewrite_rule?

add_rewrite_rule is for converting a URL structure to query vars and routing requests through index.php, you can’t point to other URLs and use flags like you would in htaccess rewrites. for what you’re trying to achieve, doing it via htaccess is the simplest way. your rule should work if you just remove the leading slash: … Read more

Change settings of get_post_type_object

since WP 4.4.0, you can use this filter that allows you to change the arguments used in the original cpt registration. Add this to your functions.php file: add_filter( ‘register_post_type_args’, function( $args, $post_type ) { if( ‘wyde_portfolio’ === $post_type && is_array( $args ) ) $args[‘rewrite’][‘with_front’] = false; return $args; }, 99, 2 ); It’s taken from … Read more

Default category link for a custom category is a broken link

I found that the reason flush_rewrite_rules(); wasn’t working was because switch_to_blog doesn’t re-initialize some of the properties of $wp_rewrite (not to mention other parts of WP), so flush_rewrite_rules was still generating some of the rules based on the permalink structure of the current blog (which is not the same), rather than the switched-to blog (84). … Read more

How to properly rewrite url by custom var

So, first off, never flush rewrite rules on every page load. Better to do it on plugin activation one time. Step 1: add the rewrite rule: add_action( ‘init’, ‘wpse26555_add_rewrite’ ); function wpse26555_add_rewrite() { // You should probably rewrite to index.php instead of shop.php? add_rewrite_rule( ‘/shop/brand/([^/]+)/?$’, ‘index.php?brand=$matches[1]’, ‘top’ ); } Step 2: add the query var … Read more

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