Question

My site runs on the latest version of WordPress. However, I have a problem with categories. Permalinks are set correctly and my category path looks like this: example.com/category-name. Links work fine, but the problem is, I can also access every category with a link like this: example.com/example.com/?cat=6, which contains no posts.

I feel like I've tried everything to fix it. "siteurl" and "home" fields in the database are set correctly (https://example.com), as well as permalinks. It's not plugin nor theme related - I checked everything.

Does anyone have any ideas how to fix this?

Was it helpful?

Solution

You can "workaround" the issue with a redirect in .htaccess, although it's not clear why this double-domain-URL would be accessible in the first place.

So, we can redirect URLs of the form example.com/example.com/?cat=6 to example.com/?cat=6, which you then say is correctly redirected to example.com/category by WordPress.

For example, at the top of your .htaccess file:

RewriteRule ^(?:www\.)?example\.com/(.*) /$1 [R=301,L]

This basically removes example.com (or www.example.com) from the start of the URL-path. Any query string that was present on the initial request (eg. cat=6) is passed through to the target URL by default.

Test first with a 302 (temporary) redirect to avoid potential caching issues.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top