assuming u
is a custom query var, you have to first add it to the array of recognized query vars:
function wpa_query_vars( $query_vars ){
$query_vars[] = 'u';
return $query_vars;
}
add_filter('query_vars', 'wpa_query_vars');
Then add an internal rewrite rule that accepts anything appended to vendors
and passes that as the u
query var:
function wpa_rewrite(){
add_rewrite_rule(
'vendors/([^/]+)/?$',
'index.php?pagename=vendors&u=$matches[1]',
'top'
);
}
add_action( 'init', 'wpa_rewrite' );
Make sure to flush rewrite rules once for this rule to be added, you can also do this by just visiting the Settings > Permalinks
admin page.
Then in the template, you can access the value of u
via get_query_var()
:
$vendor = get_query_var( 'u' );
Related Posts:
- How to add custom rewrite rule to .htaccess?
- SEO Friendly URLs for my plugin categories
- Custom rewrite rules are sending everything to index.php
- WordPress keeps writing rewrite rules to .htaccess
- Dynamic URL, not a physical page within the database
- Custom rewrite rule
- hard flush_rewrite_rules() not regenerating .htaccess
- Map alt domain to specific section of website w/o MU
- Rewrite rule to load images from production does nothing
- WordPress rewrite rules don’t need ^?
- Url Rewriting a dynamic wordpress page
- My WP_options db rewrite_rules Does Not Work
- Disable Pagination on Pages
- .htaccess rewrite
- Changed pagination URLS to use p= instead of paged=
- Rewriting “pretty” blog category URL with htaccess / add_rewrite_rule() causes 404 page
- WordPress keeps writing rewrite rules to .htaccess
- Customise particular RSS permalink
- RSS feed rewrite matching wrong rule
- Rewrite specific action url
- How do I make WordPress revise an .htaccess file a certain way?
- Rewrite rule that wp-login.php?action=register is left alone
- Pretty URL via Rewrite
- Migration from old CMS to WordPress 301 redirection rules?
- Additional .htaccess rules based on wp page
- What is the proper way to use add_rewrite_rule to remove the (question mark)?
- Can’t get pretty permalinks to work without index.php
- Rewrite Page Parameters
- WP-Include rewrite directory
- How do you create a “virtual” page in WordPress
- Rewrite rules not working in WordPress
- Preserving $_GET parameter while using custom Rewrite Rule
- Taxonomy rewrite question
- How do I remove a word from a url in WordPress using .htaccess?
- Rewrite rules in .htaccess get overwritten?
- Getting add_rewrite_rule and add_rewrite_tag to work
- Rewrite Rule for Custom Page with Query Vars in URL
- Rewrite Rule for Post “Subpage”, with pagination
- WP Rewrite the last two parts of the URL
- WordPress redirection to get url friendly
- Rewrite WordPress Custom URL
- Access $_POST data after redirect
- Change Query String to pretty permalink
- add_rewrite_rule not working for language specific characters
- How to add a custom redirect rule for subdomains?
- Remove special characters in a URL
- Alias ‘wp-content’ directory to something shorter (framework?)
- Rewrite URL – insert custom variables as a directory path
- How to properly rewrite url by custom var
- Can’t add external rewrites
- url rewrite parsing a custom url parameter not working
- How to add custom variable in url without redirect?
- Using category slug in add_rewrite rule
- add_rewrite_rule ignoring other params than the “p” param
- How to catch Rewrite rules then display a specific post?
- Adding two rewrite rules
- Load an url with minimal/no DB queries
- Monkey Man Rewrite Analyzer says my rule will trigger but it doesn’t [closed]
- Auto generate rewrite rules for multiple taxonomies
- Change htaccess to redirect to index.php in subfolder
- Cannot access wp-admin without trailing slash – .htaccess configuration for WordPress behind a nginx proxy
- Wildcard forward all posts and pages with few exceptions
- Help with Rewrite Rule for Custom Post Type with Query String
- Rewrite URLs – Custom Post Type – Post Slug, Taxonamy Slug
- URL Rewriting for PHP script on an image URL
- Create Dynamic SEO Friendly URL for Virtual Page
- Replace specific middle part of url
- Rewrite query string to path
- Rewrite API -Adding a parameter before the slug
- Help with rewrite rules for two post types
- Rewrites rules disappear after a while
- Rewrite vs Redirect from ?p={ID}
- Adding a rewrite rule to page that has no fixed variables and pagination
- Flush rewrite rules on option update with Settings API
- Having WordPress control only certain pages with .htaccess?
- Localize URL bases
- Help with a custom rewrite
- Using URL rewrite to add custom URL for custom post type
- WordPress simple Url Rewrite
- 301 Rewriting htaccess
- Rewriting in wordpress url
- Proper way to set up rewrite with Wp
- Why is a rewrite rule in wordpress prevent pagination?
- Rewrite custom taxonomy slug – but only parent items
- Exclude subfolder in WordPress permalink
- wordpress path generation from rewrite rule
- WordPress is adding “category” word before my actual category name in url (and this is unsolicited)
- Rewrite WordPress Url from root to subfolder without moving files
- WordPress pagination broken for page 2,3 with custom permalink. Redirects to baseurl
- Help with .htaccess setup to hide WordPress Directory
- Ugly URLs when there’s pagination
- How do I rewrite URL that has custom parameter
- Why is there a 404 on page 2+ for my search page?
- Rewrite rule for post as a child of a CPT
- URL Rewrite and Archive Template Files – Post Type vs. Taxonomy
- .htaccess RewriteBase equivalent for WordPress – Passing a URL as a variable without getting a 404
- Change Admin URL
- URL Rewrite for CPT single posts
- Rewriting WordPress URLs
- How to rename the WordPress wp-login.php running on IIS6?