To be added on init
:
To register your custom variable (‘id’ in the question)
add_rewrite_tag('%mycustomvar%','([^&]+)');
To create a re-write rule:
add_rewrite_rule('^product/([0-9]{1,})/?','index.php?p=4&mycustomvar=$matches[1]','top')
4 is the id of the ‘product’ page. You will need to flush rewrite rules once after adding these (go to Permalink settings page)
You can get the value of mycustomvar
: get_query_var( 'mycustomvar' )
.
See Codex for:
Related Posts:
- Use a template file for a specific url without creating a page
- Passing parameters to a custom page template using clean urls
- Using a page template without a page
- Create built-in pages without creating actual pages
- Prevent WordPress from Rewriting URL for one template
- Create Dynamic SEO Friendly URL for Virtual Page
- Rewrite rules automatically for pages using specific template
- Capturing /page-name/[0-99999] in both template and number
- Pass parameters to static home page brings up index.php latest posts
- How to show one page with two different templates
- Using custom url parameters in a page
- Show index.php template instead of 404 page template
- How to create dynamic URLs on WordPress?
- How to redirect to a login virtual page?
- Get parameters and custom page template
- Add dynamic url with external page in WordPress
- Get content from other database table based on an ID and rewrite URL
- Rewrite Slug for CPT Archive Pages to Plural Name of Slug
- Change author base slug for different roles
- Dynamic Endpoints
- How to change default page slug?
- Rewrite url for custom post type
- add_query_vars and add_rewrite_rules
- WordPress URLs without posts
- Need help with rewrite_rules_array
- Hijacking the URL for filtering
- How to change ?lang=cn into /cn/
- Sub domain redirection to taxonomy
- custom htaccess rewrite rule for page
- Change URL for Blog?
- Sorting archive pages with “pretty” URLs?
- add_rewrite_rule again
- How to change page URLs to “www.site.com/page” instead of “example.com/blog/page” but keep post URLs as “example.com/blog/post”?
- Redirecting all old links from previous EE site to new WP site in one go?
- Two “.htaccess” Files Located in Different Directories?
- Evaluating a external rewrite rule before internal wordpress rewrite rule
- Removing the post format (type) slug
- Redirect all posts urls from without .html to .html
- WordPress rewrite rules for state and city
- Single Redirection Rule for Pages and Archive links
- expecting 404 but redirecting to post with url subdirectory in post title
- Rewrite of URL with ‘[‘ ‘]’ or ‘(‘ ‘)’ as literals
- Define orderby in url
- Dynamically generate child-URLs for posts or custom posts
- Preserve Domain Alias
- Mobile version issue when domain forwarding with masking
- How to building pretty URLs to reflect category hierarchy?
- WordPress Rewrites – How can I pass a variable to Custom Post Type?
- Need to add rewrite rule that adds in additional information about the post to url
- add_rewrite_rule is redirecting instead of rewriting url
- Add language prefix to permalinks
- Custom Rewrite rule to captured post (rewrite rule to rewrite rule)
- Attachment page gives 404 if user not logged
- Rewrites: .htaccess or wp_rewrite for bulk 301 changes?
- How to change the Author Slug from Username to Nickname and deal with Special Characters
- How to pass url as a parameter in a add_rewrite_rule
- Per Page Permalink Structure for Page Post Type
- Customise particular RSS permalink
- RSS feed rewrite matching wrong rule
- Removing “www” from a site URL
- Custom rewrite rule not working
- Thousands of 404 errors on old posts due to embedded links
- WP Rewrite for a custom variable
- Creating a folder structure
- How to Detect That WP is Using Mod Rewrite or $_GET variables?
- How can I allow trailing slashes on some URLs without a redirect, but not on others?
- Can’t use a specific custom URL (slug)?
- How do I get posts to appear at mydomain.com/blog?
- rewrite rules and capturing
- Adding the amp url prefix to the beginning
- Redirect to new domain that serves new and different content
- How to change search page url so that it still returns a page when there’s no search query specified?
- Custom taxonomy named ‘tag’ return 404 page
- Multiple permalink with and without category for same post
- Custom Params in URL
- Help adding custom url, rewrite_rules_array
- Implementing geotargeting while using a single database
- Url rewrite, add rule, redirect as POST request?
- Broken page redirect
- Add query arg for pretty permalinks in wordpress way
- How to add 2 variable rewrite rule?
- Get custom posts by segment of the URL
- Add ReWrite from Old Pages to WordPress (remove .php)
- Remove trailing slash
- Rewrite Url to a SEO-friendly format
- Use Parent Pages for URL Structure without Landing Page
- add_rewrite Rule
- How to show my application as referral in WordPress Stats
- Fully mask *all* traces of WordPress installation subdirectory?
- Appending parameters to WordPress query string in backend
- rewrite rule of post when accessed from archives pages
- Redirect A URL Pattern In WordPress Using .htaccess
- Rewrite Question
- Change the search URL
- username in rewritten URL, howto use it in a template
- wordpress url rewrite Query Var to Static url
- Add rewrite endpoint and .htaccess
- Remove url parameter using wordpress
- Change the slug ( url ) to a sequence number starting from 0 in the custom record type?
- Change url site.it/wordpress