Here’s how I did to fix it. Added this to my functions.php
$url = $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
if($_SERVER['HTTPS']){
$url="https://".$url;
}else{
$url="http://".$url;
}
$id = url_to_postid( $url );
$url = parse_url($url,PHP_URL_PATH);
$canonical = parse_url(wp_get_canonical_url($id),PHP_URL_PATH);
if($url != $canonical){
wp_redirect(wp_get_canonical_url($id),302);
}
Basically if I hit an url that is not its own canonical, force a redirect.
@Tom J Nowell, weird but noted. Its an old website with a bunch of plugins I don’t know in detail, so I guess one of them is the culprit. Just didn’t take the time to investigate that part.
Related Posts:
- where is permalink info stored in database?
- How can I reverse engineer a Permalink to Find the Page?
- Mapping Domains to Permalinks (not multisite)
- How to remove dates from existing permalinks?
- WordPress Permalink changes to question mark (?) in URL
- How would I create a different permalink structure for pages and posts?
- My permalinks are broken! Can I use mod_rewrite to ignore a physical file?
- Can WordPress realistically handle a site with 500 ‘pages’?
- How to prevent the default home rewrite to a static page
- Is there an action for when permalinks are rebuilt?
- When creating a WordPress page, a “-2” suffix is added to new pages’ permalinks
- How to get url of a post from admin panel
- How to get a page url by a page id?
- CPT archive 404ing when using a custom taxonomy name as a variable
- How to change “permalink” structure in “WordPress Thesis” theme?
- Performance and styles not working fine after changing permalink structure
- Maintaining two permalink structures
- Rewrite user profile URL to be human friendly
- removing index.php IIS 7.5 webconfig
- Permalinks Messed up
- rewrite_rule for custom post type doesn’t affect get_permalink
- Add ‘articles’ prefix before blog posts url without affecting pagination
- 404 Page Not Found for Only One Post
- How to 301 all posts
- WordPress within specific sub-directories, implicitly not root
- Custom attachment permalink structure [closed]
- 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
- Link to blog index from template
- How to change Post ID during import
- Is there anything built into the WordPress core to enable me to get the relative path from the “permalink structure” option
- Permalink change made author archive vanished
- WordPress 404 in development area
- Get page by path – honoring permalink settings (urls w/slashes)
- Custom Permalink
- Pagination Issue – /page/2 404
- How to stop WordPress from removing & from URL?
- why some permalinks adding characters/ruining links
- Nginx Rewrite Rule:: index.html added to every permalink
- Share same Slug for a Custom Post Type and 2 Taxonomies
- Custom Post Type Yearly Archive Permalinks
- Redirect a Blogger Page URL to wordpress
- How to prevent redirect when using the term “page” in query string?
- Edit page slug after save, cause 404 by linked pages
- Return value of get_permalink(0) and get_the_title(0)
- Custom function making troubles in get_permalink for ACF relationship fields
- .htaccess rewriterule being ignored – tyring to remove dates from WP posts
- How to redirect RSS feeds to Feedburner and keep pretty permalinks?
- Apply function only if end of url has /amp/ [closed]
- WordPress Permalinks 404 bug with “next” button
- Combine category AND custom taxonomy in permalink structure
- How to add post meta to post permalink with still keeping a good performance?
- home_url on IIS missing permalink index.php
- Update the permalinks in posts (not domain change)
- permalink and add_rewrite_rule – error 404
- Page Navigation is not working with permalink structure
- Remove Parents From Permalink of Hierarchical Taxonomy
- Default Permalink Structure for Pages
- IIS7.5 URL rewrite pboblem on index page
- Category blog URL 404
- Read more block is appending /#more-{post_id} to the link
- Problems fixing a REST API 404 after Moving my WordPress Directory and updating Permalink Structure
- Edit the output of a filter
- Why does one of my pages not have the option to edit the link?
- Custom Permalink Structure for The Events Calendar
- WP permalink working, but why content doesn’t display
- Giving specific category posts its own permalink structure returns 404
- Internal forward link with add_rewrite_rule
- Adding query string to multiple page urls in a WordPress function
- I have Akamai pointing to a WordPress installation with a different URL. Is there a way to make WordPress use this for link generation?
- Issue with wp_insert_post when modifying permalinks with “.html” extension
- Change permalink structure with post id
- How to allow different authors to use same post slug?
- while changing permalink, page redirected you too many times
- how to have same rewrite rules for 2 different post type?
- How can I add my own ‘read more’ or ‘after the jump’ type of link to the article page?
- Issue with my links or permalinks
- Permalink Options does not change
- Why can’t I save permalink “360” for a page?
- Internationalize Forum Posts Without Translating Them
- How to change permalink structure and keep permalinks for old posts
- Pointing, two or more archived Blog posts to the same permalink (Single post page)
- Where is wordpress redirecting wp-admin/admin/dashboard to wp-admin and how to turn it off
- Is there a way to remove the option to modify the Slug in post.php
- Issues with WordPress permalinks
- Only homepage working correctly, 404 error on everything else
- Use shortlink as permalink
- Mystery ghost page not appearing in Admin
- Update permalinks after domain change
- Text in permalink
- custom permlink .htaccess file 404 Not Found error
- Comparing permalink to url
- How to shorten the Permalink after WP>WP blog import?
- Ugly permalinks stopped redirecting to pretty URLs
- Add segment to URL in htaccess
- Facebook like button disappears after changing the static permalink to dynamic one!
- URL issues with WordPress
- Change default URL (or permalinks) in the back-end
- How to put link on a slideshow gallery?
- changing the default structure of category & tag permalinks