I would suggest an alternative route: the rewrite API – did you know it supports external URLs*?
function wpse_199898_add_htaccess_rule() {
// No need for the caret "starts with", WP will add it
add_rewrite_rule( 'article/([/_0-9a-zA-Z-]+)$', 'http://www.domain.tld/?id=$1 [R=301,L,NC]' );
}
add_action( 'init', 'wpse_199898_add_htaccess_rule' );
*Almost. We just need a fix for WP’s quirky path prefixing:
function wpse_199898_fix_htaccess_rule( $rules ) {
return str_replace( '/http://www.domain.tld/', 'http://www.domain.tld/', $rules );
}
add_filter( 'mod_rewrite_rules', 'wpse_199898_fix_htaccess_rule' );
Related Posts:
- Best collection of code for your .htaccess file [closed]
- Improve wordpress security by hiding non public resources
- Stop WordPress and Plugins from Overwriting .htaccess
- htaccess rewrite conflict with wordpress rules and ssl
- Htaccess for Wordpess set on single subdomain
- Blog.php or how to display recent posts?
- Remove year and month in URL using .htaccess
- index.php not loading in main folder of wordpress
- Unable to access WP admin
- 404/500 error on /wp-json
- Using WordPress only for the backend, and using AngularJS as a frontend
- .htaccess for wordpress in separate folder
- WordPress mod_rewrite is canceling/overwriting my other mod_rewrite rule
- .htaccess and WordPress Admin Bar
- Blocking access to wp-login via htaccess not working
- Struggling with add_rewrite_rule
- Giving WordPress its own subdirectory – nginx
- Cannot mask WordPress page URL using .htaccess
- Question with loading 403/ 404 error pages and htaccess
- How can I make an htaccess file on a Mac? [closed]
- Why does a directive only work when it is included inside WordPress directives?
- .htaccess password protect all but one page
- New installation can’t be found due to htaccess of the original non-WordPress site
- How to fix category url 404’s after category permalink change
- WordPress: Adding Security
- How can I fetch the content of a post of my wordpress domain from an other domain?
- Case insensitive header params for API request
- Redirect Specific Wildcard Subdomain to a specific URL on another domain
- WP install in sub-dir white screen
- 301 Redirect domain Sub-folders to Subdomain subfolder
- WordPress not seeing .htaccess rules
- Override 404 page with htaccess
- Htaccess Rewrite reverts to default .htaccess file
- create a static folder independent with WordPress
- WordPress site not working after move
- what could cause the htaccess file to be modified?
- change permalink structure with htaccess without SEO impact
- Site in subfolder – all pages work except home
- Giving to wordpress it’s own directory cause login loop
- Directing subdomain to main domain and keeping the subdomain format with .htaccess
- Remove /sites/25/ from image URLS
- htaccess, site and staging in subdirectories
- How disable canonical redirect wp-signup
- WordPress sites in subfolders
- Admin Panel Slowdown After SSL Verification
- WordPress category with 404 error
- where to add redirection rewriterule in .htaccess file?
- Trouble adding directory rewrite to htaccess under wordpress [closed]
- How do I apply friendly URL permalinks to a custom WordPress template?
- Forcing HTTPS with WordPress on AWS
- WordPress Example Code for Blocking Referrer Spam
- create virtual subdomains for a bunch of urls on a site via .htaccess
- htaccess getting overwritten over and over = 404 error
- htaccess problem not being able to overwrite previous rules
- wordpress blog displaying blank pages [closed]
- Relative links stop working after moving wordpress site from hosting to localhost
- WordPress site blacklisted by Google about .htaccess [closed]
- How to fix .htaccess corrupted
- Protect wp-login, but get an internal server error
- Local wordpress install only shows home page, all other pages Not Found
- Redirect wrong links WordPress
- Accepting special characters in querystring
- Cannot access subdirectory subpages
- WordPress constantly running out of memory
- How can I create a smarter .htaccess file that will add a directory?
- WP Codex answer incomplete? Put WP in subdirectory. .htaccess change required
- .htaccess found in every folder
- All navigation links on website redirect to same page
- WordPress is removing trailing slash
- How do I properly redirect requests to WordPress subdirectory?
- Htaccess file reset automatically how to fix this issue
- Clone WordPress for testing on localhost (with Fiddler)
- Force a 403 response to xml file in WordPress
- Redirect files in uploads directory if WordPress user not logged in
- Redirect wordpress site to www from non www on wordpress server
- Update htaccess in several WP sites at once
- Pretty Url not working on the server
- How to use slug with subdomain?
- Leverage browser caching
- Reversing domain ‘sharding’ with htaccess
- WordPress URL not working?
- How to direct users to a subcatalog
- WordPress Intercepting Requests To A File In Public HTML
- How to block wordpress admin by htaccess
- Htaccess remove dates from root site but not from subdomain
- .htaccess home configuration
- Installing wordpress on subdirectory 2 levels down
- htaccess conflict between WordPress and password protected subdirectory
- Cannot Override WordPress 404 for a Sub-Directory
- Using subdomain as primary domain
- Restrict Content for only Contributors via .htaccess
- Redirect from domain.com to subdomain.domain.com
- Add-on domain works in WordPress but links still lead to subdomain
- In a subdomain network, what .htaccess settings can I use to have WP ignore requests to one subdomain?
- register_post_type and register taxonomy and htaccess
- Why ‘Authorization Required’ is coming on wordpress login
- htaccess rule to ignore specific subdomain [closed]
- Restricting direct downloads of wp content files, but allow them on the website.
- .htaccess rewrite rule stopped working for wordpress site after moving server
- Permalinks not working on debian with OVH