Permalinks not working in WordPress
After changing “AllowOverride None” to “AllowOverride All” in Apache configuration files, it works
After changing “AllowOverride None” to “AllowOverride All” in Apache configuration files, it works
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
This actually does not work great at all as the existence of the cookie does not indicate that the user is logged in, or even that he was ever logged in. All it indicates is that someone somehow set that cookie. To know that the user accessing the file is actually logged in or ever … Read more
Place this above the # BEGIN WordPress line. RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteCond %{HTTP_HOST} ^(.*)$ [NC] RewriteRule ^(.*)$ https://www.%1/$1 [R=301,L]
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
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
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
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() 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
‘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