The MU forums have moved to WordPress.org

.htaccess: subdomain.mydomain.com --> subdomain.mydomain.com/blog (3 posts)

  1. steveoc
    Member
    Posted 17 years ago #

    I have the following permanent redirect set up through cpanel:

    mydomain.com --> mydomain.com/joomla

    I have also set up wordpress mu in mydomain.com/blog using subdomains for the blogs it creates.

    I was wondering if there was a way to set it up so that:

    subdomain.mydomain.com --> subdomain.mydomain.com/blog

    so that it works for any subdomain set up by WordPress MU.

    Would I set that up in .htaccess in public_html or in the wordpress subdirectory?

    Wildcard DNS is already set up and subdomain.mydomain.com/blog works fine.

    subdomain.mydomain.com currently redirects to mydomain.com/joomla

    Thanks,

    Steve

  2. steveoc
    Member
    Posted 17 years ago #

    I have a answer that works for an individual subdomain:

    RewriteEngine on

    RewriteCond %{HTTP_HOST} ^subdomain.domain.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.subdomain.domain.com$
    RewriteRule ^(.*)$ http://subdomain.domain.com/blog [R=301,L]

    Of course, I'd have to do that for each subdomain. Is there any way for it to automatically forward:

    anysubdomain.domain.com --> anysubdomain.domain.com/blog?

    Thanks,

    Steve

  3. steveoc
    Member
    Posted 17 years ago #

    I got it. I found this:

    RewriteEngine On

    # Extract the subdomain part of domain.com
    RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]

    # Check that the subdomain part is not www and ftp and mail
    RewriteCond %1 !^(www|ftp|mail)$ [NC]

    # Redirect all requests to a php script passing as argument the subdomain
    RewriteRule ^.*$ http://www.domain.com/show-user.php?user=%1 [R,L]

    and changed the last line so that:

    RewriteEngine On

    # Extract the subdomain part of domain.com
    RewriteCond %{HTTP_HOST} ^([^\.]+)\.domain\.com$ [NC]

    # Check that the subdomain part is not www and ftp and mail
    RewriteCond %1 !^(www|ftp|mail)$ [NC]

    # Redirect all requests to the same url with /blog
    RewriteRule ^.*$ http://%1.domain.com/blog [R,L]

    This works for me. I hope someone else finds this useful!

    Steve

About this Topic