WordPress.org

Ready to get started?Download WordPress

Forums

Pretty Permalinks and Subdomains (10 posts)

  1. Azurite
    Member
    Posted 1 year ago #

    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
  2. 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 ^(.*)$ http://$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?

  3. Azurite
    Member
    Posted 1 year ago #

    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!

  4. 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$ http://blah.domain.com [L,R=301]
    RewriteCond %{HTTP_HOST} ^domain\.com
    RewriteRule ^hello$ http://hello.domain.com [L,R=301]

    And yes, you have to separate them like that.

  5. Azurite
    Member
    Posted 1 year ago #

    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.

  6. 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$ http://atw.seventh-star.net/ [L,R=301]

    (You can probably do this too:

    RewriteCond %{HTTP_HOST} ^seventh-star\.net
    RewriteRule ^(atw|blah|foobar)$ http://$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.)

  7. Azurite
    Member
    Posted 1 year ago #

    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$ http://atw.seventh-star.net/ [L,R=301]
    
    RewriteCond %{HTTP_HOST} ^seventh\-star\.net$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.seventh\-star\.net$
    RewriteRule ^indigo$ http://indigo.seventh-star.net/ [L,R=301]
    
    RewriteCond %{HTTP_HOST} ^seventh\-star\.net$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.seventh\-star\.net$
    RewriteRule ^chixflix$ http://chixflix.seventh-star.net/ [L,R=301]
    # END WordPress
  8. No, you can't do that.

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

    You can only have ONE condition and rule set.

  9. Azurite
    Member
    Posted 1 year ago #

    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.

  10. 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 ^(.*) http://halfelf.org/$1 [L,R=301]

    I explained it a little deeper here: http://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 ^(.*)$ http://seventh-star.net/$1 [R=301,L]
    
    # Redirect chixflix, dudeprude, jimbo
    RewriteCond %{HTTP_HOST} ^seventh-star\.net$
    RewriteRule ^(chixflix|dudeprude|jimbo)$ http://$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 :)

Topic Closed

This topic has been closed to new replies.

About this Topic