We have Wordpress in the root / in a physical subfolder /wp and Magento in /products.
We are wanting to make the sites multi-language using sub folders e.g domain.com/en
The problem arises as magento appends the store code (language) after the url so we have
domain.com/en (wordpress)
domain.com/products/en (magento)
Naturally we would like
domain.com/en
domain.com/en/products
Now it's very easy to make it work with some rewrite rule
RewriteRule ^(.*)/products/?(.*)$ /products/$1 [L]
But still we have an issue as Magento generates the links as /products/en it's possible to start modifying where these links are generated like in
\Magento\Store\Model\Store
In the _updatePathUseStoreView function, this doesn't seem to handle all links though
In general seems like a bad solution, another idea is to use Apache mod_substitute also seems bad practice, and overhead.
Another option is to have both apps in the root and have some lookup logic to see which url belongs to which app.
Any ideas for a setup that can purely use just Nginx/Apache. That does not compromise on having unique url's or regex'ing content.
This is my .htaccess in the root
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteCond %{REQUEST_URI} !^/wp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_URI} !^/(.*)/products
RewriteRule ^(.*)$ /wp/$1
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ wp/index.php [L]
RewriteCond %{REQUEST_URI} ^/(.*)/products
RewriteRule ^(.*)$ /products/index.php [L]
</IfModule>
The exact spec I'm trying to achieve is this.
Attempt 1 Use base link URL entering /en/products there and keeping the base URL as /products
as the first request is forwarded I had to work the setEnv like so in the root .htaccess
RewriteCond %{REQUEST_URI} ^/(.*)/products
RewriteRule ^(.*)$ /products/index.php [E=MAGE_RUN_CODE:%1] [L]
then in /products/.htaccess
RewriteCond "%{ENV:REDIRECT_MAGE_RUN_CODE}"
RewriteRule .* - [E=MAGE_RUN_CODE:%{ENV:REDIRECT_MAGE_RUN_CODE}] [L]
I checked the code was coming through on index.php by doing
echo getenv('MAGE_RUN_CODE');
In my case the store code is "en" etc.. but the language switcher does not work it hits Magento but gets 404 even thought the store code is definitely coming through.
You only need some configuration from backoffice.
System => Configuration => General => Web => Url options
Add Store Code to Urls No
System => Configuration => General => Web => Unsecure
Base Link URL http://example.com/en/products/
System => Configuration => General => Web => Secure
Base Link URL https://example.com/en/products/
Then, add a rule in htaccess to set the correct store code:
SetEnvIf Host .*example.com/en* MAGE_RUN_CODE=en_store
SetEnvIf Host .*example.com/fr* MAGE_RUN_CODE=fr_store
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With