humanmade / Mercator

WordPress multisite domain mapping for the modern era.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Why does alias include subfolder ?

jephperro opened this issue · comments

commented

Hi there,

I've set up a brand new multi-site Wordpress instance and installed the Mercator plugin following the instructions.

My wordpress instance uses subfolders. I set up an alias for one of the sites ( not the root site ) and when I visit the site, the

So, for example:

root-site.mydomain.com is the root

root-site.mydomain.com/myfirstsite is the site
I set up an alias of myfirstsite.mydomain.ca for the site

When using a browser to navigate to myfirstsite.mydomain.ca , I am redirected to myfirstsite.mydomain.ca/myfirstsite

Is this the expected behavior ? Or have I set up something incorrectly ? In Apache I have set up VirtualHosts for the alias to point at the same path as the root site.

Thanks

commented

image

image

@jephperro that's not expected behaviour but may depend on a few other aspects of your config. I'll see if I can reproduce it locally first.

I am also having this issue - when creating an alias the subfolder appears when using the domain alias. e.g http://www.mynewdomain.com/site-directory/ - need a way of removing the sub-folder from the URL.

the same issue exist for me.

The reason why this happens is in the implementation of the mangle_url function. It uses preg_replace to replace the host from the site URL and home URL option with the domain from the domain mapping database table.

// Replace the domain
$domain = parse_url( $url, PHP_URL_HOST );
$regex = '#^(\w+://)' . preg_quote( $domain, '#' ) . '#i';
$mangled = preg_replace( $regex, '${1}' . $current_mapping->get_domain(), $url );

As you can see, the code only changes the host of the URL and leaves everything else untouched. So, if the home/site URL of a subsite is set to http://networkdomain.com/subsite, then the filter will change that to http://subsite.com/subsite.

so how does one fix this issue then? I'm experiencing the same thing.

@JustThomas thanks for getting to the root of the issue - should be an easy fix from there!

@NICrichard hang in there, I can patch this shortly.

I'll make a new release for this, will be 1.0.2