tl; dr
I have a Magento install on www.example.com
I have a Wordpress install on www.example.com/wordpress
And I need the following urls to also serve that same wordpress content;
www.example.com/eu/wordpress
www.example.com/gb/wordpress
P.S.: I know there are duplicate content issues with this, please ignore that
The question is: What's the best way to do that?
The full story
I have a Magento multi store site using the 2 digit language code subdirectory technique.
I have one Wordpress installation in it's own subdirectory.
app
downloader
errors
eu/ - symlinks for the € Euro store
gb/ - symlinks for the £ UK store
includes
js
lib
media
shell
wordpress/ - The Wordpress install
var
I need the Wordpress blog to be available from all stores so they user stays in the store with their locale/currency.
What I have Tried
Using the answers in these Stacks;
htaccess multi language site with sub directories, and default 301
Endless Redirect Loop by htaccess rules multi language
I've made attempts but unfortunately I am terrible with .htaccess and vhosts problems
Via the vhosts file
<VirtualHost *:80>
ServerName www.example.com/eu/wordpress/
ServerAlias www.example.com/wordpress/
DocumentRoot /var/www/vhosts/www.example.com/public/wordpress
</VirtualHost>
<VirtualHost *:80>
ServerName www.example.com/gb/wordpress/
ServerAlias www.example.com/wordpress/
DocumentRoot /var/www/vhosts/www.example.com/public/wordpress
</VirtualHost>
Via the Wordpress htaccess
RewriteCond %{REQUEST_URI} !^/(eu|gb )/wordpress(/|$) [NC]
RewriteRule ^(.*)$ wordpress/$1 [R=301,L]
Via the Magento .htaccess
RewriteCond %{REQUEST_URI} ^/eu/wordpress/(.*)$ [OR]
RewriteCond %{REQUEST_URI} ^/gb/wordpress/(.*)$ [OR]
RewriteRule ^/wordpress/.*$ - [L]
Firstly, you don't need vhosts for wordpress, you need only one vhost per domain and/or subdomains. Your vhost should look something like this(which I assume that you already have a vhost similar to this for your magento shop):
Now, you just need to modify magento's .htaccess(/var/www/vhosts/www.example.com/public/.htaccess), and add the following rules:
We have this in production, hopefully this answer might help someone at some point.
The way we've done this is to add a RUN_CODE environmental variable which is used in a custom Wordpress filter to get the urls all working. I've used the 'eu' example from my question to illustrate it below. Note we had to do this for both Apache and Nginx so I've added the .htaccess and server blocks for both.
APACHE - .htaccess
In the
eu
country stub subdirectory you add this to your .htaccess file (so eu/.htaccess)NGINX - Server Block
In the Wordpress root
index.php
this was added at the top of the fileWordpress theme
functions.php