You can’t match the query string using a mod_alias RedirectMatch
directive. This directive matches against the URL-path only. You need to use mod_rewrite instead, with a condition that checks the QUERY_STRING
server variable.
For example, at the top of your .htaccess
file, try the following:
RewriteCond %{QUERY_STRING} ^page_id=\d+$
RewriteRule ^$ / [QSD,R=302,L]
The QSD
flag (Apache 2.4) is required to remove the query string from the target URL.
However, from an SEO perspective, mass redirections like this will likely be seen as soft-404s by the search engines. You should try to redirect on a per page basis to the new URL. If the content no longer exists then return a 404.
Related Posts:
- WordPress Redirect All HTTP requests to HTTPS via .htaccess
- Old blog/ and blog/feed/ URLs not working after moving blog to top-level via .htaccess
- Non-WordPress page in subdirectory under WordPress page
- Force HTTPS using .htaccess – stuck in redirect loop
- 301 redirect not working through .htaccess
- How to redirect url requests to https? [closed]
- Redirecting old permalink to new one
- 302 redirect instead of 301 after switch to HTTPS
- How do I skip wordpress’s 404 handling?
- Problem to redirect custom page using htaccess
- htaccess redirect not working
- htaccess wildcard redirect misses some URLs
- Redirect from https to http or from http to https? [closed]
- Redirect too many times htacces switching to https
- How to do 301 redirect to Sub page using htaccess file?
- Can WordPress redirect to a “similar page” in case of 404 error
- Hacked website redirect, only on desktop, help with restoring it [closed]
- How to hide that a certain non-WordPress directory exists on the server?
- Redirect “any page/page/number/” to “any page”
- How to create a 301 redirect that doesn’t apply to subsites
- WordPress multisite htaccess redirection to new domain
- WordPress blocking/preventing viewing of .cgi file in subdirectory [closed]
- https redirect (with .htaccess) redirect loop
- Deny access to a path (give 403 or 404 response)
- htaccess 301 redirect http to https doesn’t work
- Redirect home to another page with htaccess
- 301 Redirect Loop
- Redirecting old post url to 404 in wordpress using htaccess
- Headless WordPress redirect front-page to login page [closed]
- How to redirect subcategories to a page?
- Use htaccess to redirect WordPress to static website in a subfolder
- 301 Redirect To Post ID
- CNAME vs A Record for WWW – with 301 Redirects
- set up 301 redirect within wp-content/uploads/ directory of a WP site to a new image URL
- Redirect from sub-directory to root – New WordPress 5.2.3 Set up
- How to add new redirection on wordpress site
- .htaccess rule to redirect old URLs to new structure [closed]
- How to redirect URL with subfolder to the same URL but without subfolder?
- .htaccess Redirect
- What is the right way to redirect all traffic to HTTPS?
- Site loads very slowly (4-5 minute load time)
- How can I redirect a URL to an anchor link while maintaining the URL?
- How to remove duplicate and unnecessary part in a url using htaccess and regex?
- Redirect homepage with htaccess, except if I enter the link adding “/home”
- 503 Service Unavailable error was encountered
- SSL and www to non-www redirection works only on homepage – WordPress
- Built-In Postname Redirection vs Hard Redirects in relation to SEO and performance
- Redirecting old permalink structure to new in htaccess
- WordPress keeps redirecting subpages without http to https homepage after switch
- How To Fix A Redirect Chain
- 301 Redirect all page and post urls from .html to /
- Redirect “http://old.net/category/postname” to “https://new.com/postname”?
- 301 Redirect Old URL to New WordPress Page
- How to remove the [L] Flag for WordPress index .php mod_rewrite
- URL masking of subdomain to main domain using .htaccess
- ReDirect subfolder link to another sub-folder and force SSL
- What is the most efficient (ie. less server intensive) way for 301 redirects?
- How to forward all requests starting with a specific folder name to the same folder
- How do I do a redirect to WordPress permalink with post id via htaccess?
- Issue redirecting ‘blog’ to ‘news’ in WordPress using .htaccess
- Will deleting WP’s code in .htaccess cause problems?
- Use two different index pages
- How can I redirect users on the new 404 page without plugin?
- How do I write a subdomain redirect?
- How can I redirect a request to the site root using htaccess, if there’s not a specific cookie set?
- Redirect old query string URLs to new add_rewrite_rule URL
- htaccess redirect from specific urls of my site to the homepage
- HTTPS to HTTP rewrite rules not working as expected
- Is there way to redirect all blog post pages to Home page?
- get_bloginfo prints IP instead of url
- How to redirect multiple subfolders back to root domain?
- How to redirect non existent pages/posts in wordpress using htaccess
- How do I Redirect Tags from Old Joomla Site to New WordPress Site?
- Temporary Infinite Redirect Loop
- htaccess 301 Redirect not working from aspx to new WP permalink
- A question about .htaccess
- Mass .htaccess URL Forwarding
- ErrorDocument 410 gives me back a 302 header
- WordPress not linking correctly with .htaccess redirect to subdirectory
- How to create multiple Rewrite-Rule for various site in single htaccess?
- WordPress site not forcing from http to https instead getting redirected too many times
- How to make front page temporarily show content of internal page
- Redirect only PDFs in different folders?
- Redirect HTTP request to HTTPS request
- How do I skip wordpress’s 404 handling?
- home page redirect loop after update to 4.8
- Cannot get 301 redirection in htaccess to work (either Redirect or Rewrite)
- Resolving the too many redirects on wordpress
- 301 Redirects when change URL in WordPress database
- What’s the best way to redirect to a new wordpress website?
- .htaccess not working after page slug change
- Debugging a redirect loop affecting only certain pages
- Subpages return 404 server error
- WordPress 302 Redirect to Holding Page
- WordPress on a subfolder but accessible from root
- WordPress redirect from one directory to another but exclude wp-admin and wp-login.php
- Can I redirect the http request towards an old folder to the homepage using .htaccess file? [closed]
- Redirect a WP to another with all URL
- Redirect ignore last URL segment
- Other pages fine but wp-admin showing ERR_TOO_MANY_REDIRECTS Error