WordPress Development Asked on November 6, 2021
I am trying to find out what impact setting a custom stucture prefix in permalinks has on 404’s
I have a custom structure of:
/news-opinion/%postname%/
This is working as expected if you tried to go to a page: domain.com/news-opinion/non-existing-url
I will get a 404 as expected.
However if I use: domain.com/non-existing-url
this will redirect a user back to the homepage and not 404.
Am I missing somthing here I should have accounted for?
This is a Bedrock / Composer based install and this is the list of plugins in use if any of these are known to cause this issue:
"wpackagist-plugin/cache-enabler": "^1.3.4",
"wpackagist-plugin/classic-editor": "1.5",
"wpackagist-plugin/relevanssi": "4.2.0",
"wpackagist-plugin/safe-svg": "1.9.4",
"wpackagist-plugin/wp-mail-smtp": "^1.8",
"wpackagist-plugin/instant-images": "4.2.0",
"wpackagist-plugin/shortpixel-image-optimiser": "4.16.1",
"deliciousbrains-plugin/wp-migrate-db-pro": "^1.9",
"humanmade/s3-uploads": "^2.1",
"custom-repo/advanced-custom-fields-pro": "^5.7.0",
"custom-repo/gravityforms": "^2.4.0",
"wpackagist-plugin/duplicate-post": "3.2.4",
"wpackagist-plugin/filebird": "2.7.1",
"wpackagist-plugin/crop-thumbnails": "1.2.6",
"wpackagist-plugin/redirection": "4.7.1",
"wpackagist-plugin/advanced-cron-manager": "2.3.10",
"wpackagist-plugin/wp-seopress": "3.8.4",
"wpackagist-plugin/cookie-bar": "1.8.7",
"custom-repo/vcaching": "^1.8.0",
"wpackagist-plugin/wordpress-importer": "0.7",
"wpackagist-plugin/export-media-with-selected-content": "2.0",
"wpackagist-plugin/user-roles-and-capabilities":"^1.2.3",
"wpackagist-plugin/wp-all-export": "1.2.5"
If I can provide any more information that may be pertanent to this please let me know.
Any help with this would be apperciated.
OK so after much working out what was causing this, this was caused by me not setting:
fastcgi_param PATH_INFO
Which was being set as part of the hosting setup the company I work for sets.
We found this out by tracing back the cause to the class_wp.php file in particular we found that:
if ( empty( $requested_path ) || $requested_file == $self || strpos( $_SERVER['PHP_SELF'], 'wp-admin/' ) !== false ) {
$self and $_SERVER['PHP_SELF'] were coming up as index.php for my local copy but on the hosting environment these values were matching the $requested_path.
So nothing to do with plugins etc.
Answered by Sam on November 6, 2021
It is normal behavior of WordPress to redirect users to 404 page when a post is not found.
Both should have got redirected to 404 page ideally:
It is strange that you are facing this issue. Would you mind trying the below steps (check the issue after each step):
If you find that after trying the above steps the issue is fixed then please activate your theme and plugins back one-by-one and also reverting to your custom permalinks settings.
Hope you can get to the problem which is causing this issue.
Answered by SagarG on November 6, 2021
So to confirm, on a fresh Wordpress install with that setup /non-existing-url
definitely returns 404, so it's not specifically the custom permalink that's the cause.
It may be worth posting your .htaccess
in case it's been modified.
However I'd suspect that one of the plugins you have is helpfully adding this feature, and I'd suggest temporarily disabling Redirection and SEOPress to see if it's them. Once you figure out which one it is you can see if there's a way to disable this specific behaviour in that plugin
If you want to, it would be easy to manually add an .htaccess rule to make /anything
404, but that puts a fix on top of a problem and will quite possibly break other things, so I agree with the point of your post which would be figure out what's doing it if possible.
EDIT: Query Monitor shows you which URL rules the current page matched against, however I don't know if it'll be useful here where there's a redirect. Worth knowing about if you don't already as it's a great tool for debugging URL rewrite issues.
Answered by mozboz on November 6, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP