The MU forums have moved to WordPress.org

Weird subdomain setup(subfolders = subdomain) and I need help from experts. (6 posts)

  1. uno
    Member
    Posted 14 years ago #

    I have the following setup to attempt to get blogs to work like this: wordpress mu(latest version) is setup on in domain.com/blog/ I have it set up so new blogs are set up as subdomains x.domain.com/blog/. The blogs themselves seem to work superficially from that address. I have existing niched sites set up in x.domain.com (or domain.com/x/) so I can add and edit things in the folder structure for SEO and the like. When I click on any of the links or the post titles, archives, tags, whatever in x.domain.com/blog/ it redirects to x.domain.com.

    My hosting company is completely perplexed as to how to fool with the rewrite rules to get this working correctly. It was hard enough to get wordpress mu to work with my structure in the first place. If you guys have any advice, explanations or answers, it would be greatly appreciated. *domain.com isn't actually the domain, just an example.

    This is in my apache config

    RewriteEngine On
    # mod_dir fix
    RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
    RewriteCond %{HTTP_HOST} ^(.*\.)?([^\.]+)\.domain\.com$ [NC]
    RewriteCond %{DOCUMENT_ROOT}/%2%{REQUEST_URI}/ -d
    RewriteRule [^/]$ http://%2.domain.com%{REQUEST_URI}/ [R=301,L]

    # strip sub subdomains
    RewriteCond %{HTTP_HOST} ^.*\.([^\.]+\.domain\.com)$ [NC]
    RewriteCond %{REQUEST_URI} !^/blog
    RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

    # abc.domain.com/def --> /subs/abc/def
    ##RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
    RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]
    RewriteCond %{DOCUMENT_ROOT}/%1/ -d
    RewriteCond %{REQUEST_URI} !^/blog
    RewriteRule ^(.*)$ /%1$1 [QSA,L]

    RewriteLog /var/log/httpd/rewriter.log
    RewriteLogLevel 9
    #UseCanonicalName off
    #VirtualDocumentRoot /home/httpd/html/domain.com/%-2.0.%-1/%-3

    This is in my document root

    <Files feed>
    ForceType application/x-httpd-php
    </Files>

    <Files visit>
    ForceType application/x-httpd-php
    </Files>

    ErrorDocument 403 http://www.domain.com/
    ErrorDocument 404 http://www.domain.com/

    #This part changes and subfolders to use subfolder.domain.com
    RewriteEngine on
    #RewriteCond %{REQUEST_FILENAME} -d
    #RewriteCond %{REQUEST_FILENAME} !^/$
    #RewriteCond %{REQUEST_FILENAME} !^$
    #RewriteRule (.*)/? http://$1.domain.com/ [R]

    #This changes the document root of part.domain.com to a folder
    #RewriteCond %{HTTP_HOST} !^www. [NC]
    #RewriteRule %{HTTP_HOST} (.*).domain.com [NC]
    #RewriteRule (.*) /%1/$1 [R]

    This is disabled in my subdomain/blog directory

    RewriteEngine On
    RewriteBase /blog
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) /blog/index.php [L]

  2. andrea_r
    Moderator
    Posted 14 years ago #

    I guess I'm scratching my head as to why you need this setup? Maybe if I knew the reasons behind it I can give a better answer.

  3. uno
    Member
    Posted 14 years ago #

    i have existing sites at x.domain.com and x.domain.com/keyword.html x.domain.com/keyword2.html etc for SEO purposes. I also want these sites to have corresponding blogs at x.domain.com/blog/

    I'll post my root and /blog dir .htaccess files in a sec.

  4. uno
    Member
    Posted 14 years ago #

    Root of domain.com:

    <Files feed>
    ForceType application/x-httpd-php
    </Files>

    <Files visit>
    ForceType application/x-httpd-php
    </Files>

    ErrorDocument 403 http://www.domain.com/
    ErrorDocument 404 http://www.domain.com/

    #This part changes and subfolders to use subfolder.domain.com
    RewriteEngine on
    #RewriteCond %{REQUEST_FILENAME} -d
    #RewriteCond %{REQUEST_FILENAME} !^/$
    #RewriteCond %{REQUEST_FILENAME} !^$
    #RewriteRule (.*)/? http://$1.domain.com/ [R]

    #This changes the document root of part.domain.com to a folder
    #RewriteCond %{HTTP_HOST} !^www. [NC]
    #RewriteRule %{HTTP_HOST} (.*).domain.com [NC]
    #RewriteRule (.*) /%1/$1 [R]

    /blog .htaccess:

    RewriteEngine On
    RewriteBase /blog

    #uploaded files
    RewriteRule ^(.*/)?files/$ index.php [L]
    RewriteCond %{REQUEST_URI} !.*wp-content/plugins.*
    RewriteRule ^(.*/)?files/(.*) wp-content/blogs.php?file=$2 [L]

    # add a trailing slash to /wp-admin
    RewriteCond %{REQUEST_URI} ^.*/wp-admin$
    RewriteRule ^(.+)$ $1/ [R=301,L]

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule . - [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-.*) $2 [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
    RewriteRule . index.php [L]

    <IfModule mod_security.c>
    <Files async-upload.php>
    SecFilterEngine Off
    SecFilterScanPOST Off
    </Files>
    </IfModule>

  5. andrea_r
    Moderator
    Posted 14 years ago #

    How are you creating the subdomains? Did you follow the wildcard directions?

  6. uno
    Member
    Posted 14 years ago #

    fixed it. vhosts was set to "no". I changed it to "yes" and everything works just fine. About 15 people, including myself, missed the most obvious thing for over a month.

About this Topic