• I’m using WPMS and have several blogs installed via the subdomain method, e.g. blah.mydomain.com and hello.mydomain.com. I only use the one domain. I’m wondering if it’s possible to have redirects, so that if someone trying to visit mydomain.com/blah or mydomain.com/hello, they’ll get redirected to the appropriate subdomain blog, instead of the “Well, this is somewhat embarrassing…” 404 page that WordPress spits out.

    I don’t intend to use categories or other things that might go into a permalink that have the same name as my sites.

    My Permalinks are currently set to Day and Name, and I’ve tried saving and re-checking, but the issue persists. I’ve checked my Redirects as set up in cPanel, and tried adding and deleting them, but it still gives me the 404 page.

    Here’s my HTaccess:

    # BEGIN WordPress
    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    
    # uploaded files
    RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule . index.php [L]
    # END WordPress
Viewing 9 replies - 1 through 9 (of 9 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    I only use the one domain. I’m wondering if it’s possible to have redirects, so that if someone trying to visit mydomain.com/blah or mydomain.com/hello, they’ll get redirected to the appropriate subdomain blog, instead…

    So mydomain.com/blah goes to blog.mydomain.com/blah ?

    That’s slightly problematic. The normal approach is this:

    RewriteCond %{HTTP_HOST} ^domain\.com
    RewriteRule ^(.*)$ https://$1.domain.com [L,R=301]

    But that would break WP, since it needs to use domain.com/wp-admin….

    You could edit the 404 page to redirect, though. Just grab the URL people are using and trim that?

    Thread Starter Azurite

    (@azurite)

    To be clear, my domain is seventh-star.net (the main network blog). I have several subsites that are also WordPress sites, including atw.seventh-star.net. Formerly, I directed people to that blog with the URL seventh-star.net/atw which now brings up a 404 WordPress page.

    How would I go about editing the 404 page to redirect where it wouldn’t apply to every mistyped URL or something?

    And what do you mean by “grab the URL people are using and trim that”? I know what possible URLs might still be in use vs. what WordPress is using, but trim them how? With/for what?

    Thank you for your help and clarification!

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    I know what possible URLs might still be in use vs. what WordPress is using

    If you only have a set list of URLs to redirect, that’s easier, if time consuming.

    RewriteCond %{HTTP_HOST} ^domain\.com
    RewriteRule ^blah$ https://blah.domain.com [L,R=301]
    RewriteCond %{HTTP_HOST} ^domain\.com
    RewriteRule ^hello$ https://hello.domain.com [L,R=301]

    And yes, you have to separate them like that.

    Thread Starter Azurite

    (@azurite)

    So the RewriteRule only mentions the actual, existing WordPress install, not the one people might try and go to?

    The only URL people might try to use (incorrectly) is this one: seventh-star.net/atw instead of atw.seventh-star.net

    That’s what I’m trying to “plan” for.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    The RewriteCond says ‘If someone comes to THIS domain…’

    And the ReWrite Rule says ‘… and if they go to this page…’

    So:

    RewriteCond %{HTTP_HOST} ^seventh-star\.net
    RewriteRule ^atw$ https://atw.seventh-star.net/ [L,R=301]

    (You can probably do this too:

    RewriteCond %{HTTP_HOST} ^seventh-star\.net
    RewriteRule ^(atw|blah|foobar)$ https://$1.seventh-star.net/ [L,R=301]

    Which will take seventh-star.net/atw, /blah AND /foobar and redirect them correctly, but test is first.)

    Thread Starter Azurite

    (@azurite)

    I tried both methods, but neither seem to work; I get the same 404 message.

    I tried seeing if having the dash in my domain name escaped would make a difference, but it doesn’t seem to. This is what I mean:

    RewriteCond %{HTTP_HOST} ^seventh\-star\.net$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.seventh\-star\.net$

    I also tried putting individual RewriteCond and RewriteRules like so, but it didn’t seem to help:

    # BEGIN WordPress
    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    
    # uploaded files
    RewriteRule ^files/(.+) wp-includes/ms-files.php?file=$1 [L]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule . index.php [L]
    
    #FOR OLD URLS THAT ARE NOW WORDPRESS SITES
    RewriteCond %{HTTP_HOST} ^seventh\-star\.net$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.seventh\-star\.net$
    RewriteRule ^atw$ https://atw.seventh-star.net/ [L,R=301]
    
    RewriteCond %{HTTP_HOST} ^seventh\-star\.net$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.seventh\-star\.net$
    RewriteRule ^indigo$ https://indigo.seventh-star.net/ [L,R=301]
    
    RewriteCond %{HTTP_HOST} ^seventh\-star\.net$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.seventh\-star\.net$
    RewriteRule ^chixflix$ https://chixflix.seventh-star.net/ [L,R=301]
    # END WordPress
    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    No, you can’t do that.

    RewriteCond %{HTTP_HOST} ^seventh-star\.net$
    RewriteRule ^chixflix$ https://chixflix.seventh-star.net/ [L,R=301]
    
    RewriteCond %{HTTP_HOST} ^www\.seventh-star\.net$
    RewriteRule ^chixflix$ https://chixflix.seventh-star.net/ [L,R=301]

    You can only have ONE condition and rule set.

    Thread Starter Azurite

    (@azurite)

    So it’s one condition, one rule, not two conditions that either/or must be matched, or condition A *and* condition B, then this rule?

    I think most people won’t use the www, but that’s just my best guess.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    ?????? Advisor and Activist

    It’s one condition, one rule.

    The only time you can use either or is if you use () variables.

    Like I have this:

    RewriteCond %{HTTP_HOST} ^(code|tech)\.ipstenu\.org
    RewriteRule ^(.*) https://halfelf.org/$1 [L,R=301]

    I explained it a little deeper here: https://halfelf.org/2012/htaccess-anarchy/

    Anyway. You could probably get away with this:

    # permanently redirect from www domain to non-www domain
    RewriteCond %{HTTP_HOST} ^www\.seventh-star\.net$ [NC]
    RewriteRule ^(.*)$ https://seventh-star.net/$1 [R=301,L]
    
    # Redirect chixflix, dudeprude, jimbo
    RewriteCond %{HTTP_HOST} ^seventh-star\.net$
    RewriteRule ^(chixflix|dudeprude|jimbo)$ https://$1.seventh-star.net/ [L,R=301]

    That will let you have fewer rules and improve your SEO by forcing one version of www vs non www ??

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Pretty Permalinks and Subdomains’ is closed to new replies.