Double domain name in category URL-s

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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x