WordPress + Magento .htaccess ReWriteRule Issue (www vs. non-www)

I have an issue I’ve been facing for a bit now. Moved away from it, but now I’m back and just have no idea after trying to find a solution online. It seems individuals have faced similar issues, but trying out common fixes has resulted in just 500 Internal Server Errors.

I’ll try to be as thorough as possible in my explanation.

OK, so onto the issue.

I have a site using WordPress and Magento. The WP pages are kept in a subdirectory (/about/) so when a user accesses one of the pages, the url looks like this: www.example.com/about/wordpresspage/. We have a products page that is kept outside of WP and is accessed directly, the url looks like this: www.example.com/magentoproductpage/.

The issue arises when a user tries to visit the non-www url.

If I remove the “www.” from the magento page url (example.com/magentoproductpage/) I am redirected to www.example.com/index.php. I know why this occurs but don’t have a fix for it, yet.

The more apparent issue is when trying to access a WP page without “www.”.

So let’s say I remove that from my previous example (example.com/about/wordpresspage/) I am redirected to a 404 page, and furthermore the URL now becomes this: example.com/cgi-bin/php/about/index.php

This only seems to occur in Google Chrome and not in Firefox. Obviously the idea here is that I just want to add www. to non-www URLs.

Any suggestions? Thanks in advance.

1 Answer
1

If you are using any CDN service like Cloudflare, then you can use the forwarding URL feature

I mean you can set this rule:

*example.com/*

https://www.example.com/$2

this way, the HTTPS and www will be added to all URLs, this can be handled via web server too, but using a CDN service, will reduce the load of your webserver

Leave a Comment