Search code examples
wordpress.htaccessdnsmultisitewildcard-subdomain

Wordpress Multisite - Redirect Subdomain to root with .htaccess


I've changed our website to a wordpress multisite. On my localhost everything worked like it should. But on our production site I'm having some problems.

The normal site works after the new setup (example.com) but when I create a subdomain site (en.example.com) I'm getting a 500 Internal Server Error. The domain mapping should be fine. (I've directed a wildcard to the ip of our server) The problems occures with the subdomain. So it seems so that our host directs subdomains always (I can't change anything) to a subfolder. /www/en for example.

As far as I know a wordpress multisite needs to be directed to the root of the wp installation to get it to work. Is there any way to get that working with the .htaccess file in the subfolder?


Solution

  • So it seems so that our host directs subdomains always (I can't change anything) to a subfolder. /www/en for example.

    You can't "fix"1 this unless you have access to the server config. But if you have access to the server config you'd change the DocumentRoot of the subdomain to begin with.

    1 By "fix" I mean internally rewrite the request to the parent directory (ie. one directory above the subdomains DocumentRoot directory). In .htaccess you can't rewrite the request above the document root - you can only do this in a virtualhost or server context, where you can rewrite to an arbitrary filesystem path. But, as mentioned, the real "fix" is to change the DocumentRoot of the subdomain.

    Only being able to create subdomains that point to subdirectories off the main domain's document root is rather limiting.

    The domain mapping should be fine. (I've directed a wildcard to the ip of our server)

    Ordinarily, you'd do the same "wildcard" thing in your <VirtualHost> container so that your server accepts requests to these "subdomains", without having to manually configure each one.

    ServerAlias *.example.com
    

    OR, you configure the default vHost or main server config to accept all requests for all hosts - but this implies you have a dedicated server (ie. full access), which you don't seem to have.