The p
query var expects a post ID, use name
instead. Also note that rules should only be flushed when they change, as it’s a computationally expensive operation. It’s best to do that on theme change or plugin activation, whichever is appropriate for where your code is located. You can also do this by just visiting the Settings > Permalinks page in admin.
add_action('init', 'add_my_rewrite');
function add_my_rewrite() {
add_rewrite_rule(
'^(.*)/server/([^/]+)',
'index.php?name=$matches[1]&server=$matches[2]',
'top'
);
}
function add_query_vars_filter($vars){
$vars[] = "server";
return $vars;
}
add_filter('query_vars','add_query_vars_filter');
Related Posts:
- Custom Rewrite with Query vars
- How to Modify Existing Rewrite Rules?
- Custom query var rewriting with only variable
- Redirect Uploads Folder to Query Vars in WordPress
- Custom permalink question
- Pretty Filter URL
- Add additional URL variations for a Post
- remove “index.php” from permalinks
- Rewrite Rule for Multilingual Website, Like qTranslate?
- Regex in add_rewrite_tag not accepting OR operators?
- How to add a custom URL placeholder to author archives?
- Permalink/Pagination issue: Category base name same as page name
- URL Rewrite + Page + Custom Post Type = Unusual Redirect
- Make post slug have priority over category slug
- flexible rewrite ‘ramble’ URLs with WordPress
- add_rewrite_rule with 3 or fewer matches?
- Permalinks for WooCommerce Categories and Subcategories
- Redirect short-form URL to long-form URL (post_id to post_id + post_name)
- How to change URL structure for pagination pages?
- Rewrite rule never matching
- Rewrite-Rules not working on a vhost, everything goes to index.php
- Date archive permalink modification
- Rewrite URL Parameter And Force ‘Pretty’ Permalink
- rewrite_rule for custom post type doesn’t affect get_permalink
- Add ‘articles’ prefix before blog posts url without affecting pagination
- How to get wordpress link to fully evaluate when coming from facebook
- custom permalink/shortlink with base62 encoded post ID
- Page Attachment Permalink Structure based on Menu Order?
- query_vars in plugin not working?
- WordPress not respecting template hierarchy (fetches index.php instead of single.php or page.php)
- Call to a member function add_rule() on a non-object
- I need a custom permalink for my website
- Rewrite rule to prettify two $_GET variables while in a new endpoint from a page
- Why is add_rewrite_endpoint incompatible with /%category%/%postname%/ permalink structure?
- Re-write specific custom post type category URL to go to another page
- How to add_rewrite_rule with two parameters to a single view page?
- Rewrite Rule for default post type
- RewriteRule accepts numbers but not letters in tag
- Date Archives’ Permalinks under Category folder
- Custom Permalink
- remove sub-category of Custom Post Type from permalink structure
- add_rewrite_rule not working for me
- Is a permastruct possible on pages?
- Using WP Rewrite, but just not “getting it”
- How do I add /blog/ as a prefix to permalink structure for posts, categories & tags?
- Share same Slug for a Custom Post Type and 2 Taxonomies
- How to remove specific category from URL in WordPress
- Rewrite CPT permalinks and include WPML language
- Custom permalink leads to index page
- Need To Add Custom rewrite base url for individual user
- Rewrite URLs for LeadPages due to subdirectory installation
- Rewriting single post url; add_rewrite_rule problem?
- Permalinks only for posts
- rewrite rule to redirect to the most recent date permalink
- How to change “attachment_id” in attachment permarlink?
- How to test custom rewrite rules /permalinks?
- wordpress how to replace url /bar with foo/bar for custom post type
- Permalink for PDF of article
- Getting back a permalink from custom url
- Order custom post type posts by custom field with pretty URL
- Adding URL prefix for foreign language support
- add_rewrite_rule on default post type
- Exclude single page from permalink rule
- help to remove last trailing slash using add_rewrite_rule
- How can I set up a secondary permalink structure?
- Rewrite rule not passing variable
- permalink and add_rewrite_rule – error 404
- How to Use metada Value in Url and is it possible? [duplicate]
- Safest way to create a custom permalink
- Creating an alternate path for a page
- Rewrite Post URL so it is constructed from parent post url & child post url
- corrupted URLs – can’t leave starting page
- Create different permalinks for same post
- Multiple Taxonomy Items for Separate URLs
- Using a template file for a specific custom URL
- WordPress Multisite ABSPATH and get_home_path() to check for htaccess or web.config file
- Redirect page to homepage, keeping URL
- Added a prefix in URL permalink structure but the old structure still working!
- Permalinks Question: Adding a prefix ONLY in front of all posts with the ‘video’ post format
- Create new URL structure for custom post types
- how to have same rewrite rules for 2 different post type?
- Permalink structure /page/page/cpt-post gives 404 with pagination
- Custom Permlinks work, regular page permalinks don’t
- What permastrusture tags are generated out of the box right after creating custom post types and taxonomies?
- No Ones Been Able to Override my WordPress Rewrite Rule Issue!
- Rewrite posts url as they’re all children of a page
- Multiple Permalink Patterns for one page
- create user’s view profile link with username
- WordPress Pagination Custom Rewrite Rule for Pages
- Where is wordpress redirecting wp-admin/admin/dashboard to wp-admin and how to turn it off
- Added incorrect rewrite rule now getting an error
- Why doesn’t WP update my .htaccess file?
- Pretty Permalink for Search Queries Not Working
- Permalink broken for pages after adding rewrite rule
- WordPress permalink still not working (error or not understood?)
- Only homepage working correctly, 404 error on everything else
- standard post with extra parameter brings permalink problem
- Custom rewrites for pages and categories
- WordPress custom permalinks, pages are now 404
- Standard Htaccess directives disappear by themselves