Support » Networking WordPress » .htaccess 301 redirection for multisite

Viewing 15 replies - 1 through 15 (of 15 total)
  • Or set up the wordpress permalinks with .html at the end? (yes, you can do that)

    Thread Starter arnoldshields

    (@arnoldshields)

    My question put another way is:

    If I wanted to migrate two different sites (some php some html) to my wordpress multisite and I wanted to redirect the old pages (301 redirect) to the new pages on multisite.

    Normally the redirect would be:
    Redirect 301 /page1.html http:/www.site1.com/page1/

    but that would redirect all page1.html pages to site1 – This would be a problem with a common names like home, index, contact etc.

    headway

    (@headway)

    I’m running into the same issue. Any info on a work-around would be greatly appreciated.

    I considered using a plugin to manage redirects, but I’d rather not add yet another plugin.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    There’s no all-in-one fix. It greatly depends what you’re coming FROM and what you’re going TO.

    Check http://corz.org/serv/tricks/htaccess.php

    I’m in along the same lines. Have an existing client on standalone WP that we have converted to our multisite WP.

    In the standalone WP .htaccess, we had:

    redirect 301 /local_staff.htm /local/staff/

    Obviously we wouldn’t want all domains (using domain mapping) to follow these links.

    Also, they have about 50 client pages that have simply dropped the html

    redirect 301 /companyname.html /companyname/

    Any thoughts on how to accomplish these two needs in multisite? Would LOVE if you know of a plugin in which client (site owners) could manage their own. In the worst event that we have to do it in .htaccess, not sure how to proceed.

    Could do RewriteCond/RewriteRule but that would be tedious and I have no idea what performance effect. Could create those pages with some kind of redirect I guess, but that again would pollute the page manager.

    Appreciate any thoughts/help.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    Making redirect pages would impact performance far more than rewrites in your .htaccess.

    As I said before, all this GREATLY matters to your specifics. We’d need more detail before we could say anything of merit past it totally can be done with .htaccess.

    Make a NEW topic with the following to get started:

    What kind of Multisite? Subfolder, subdomain, mapped domains?

    What, EXACTLY, are the old URLS and what, EXACTLY, should they be now?

    In the standalone WP .htaccess, we had:

    redirect 301 /local_staff.htm /local/staff/

    Obviously we wouldn’t want all domains (using domain mapping) to follow these links.

    Also, they have about 50 client pages that have simply dropped the html

    redirect 301 /companyname.html /companyname/

    Any thoughts on how to accomplish these two needs in multisite?

    Short version: put the full url in there.

    @andrea – Thanks. Tried the full URL like this:

    # BEGIN WordPress
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    
    # uploaded files
    RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
    
    # add a trailing slash to /wp-admin
    RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule  ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
    RewriteRule  ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
    RewriteRule . index.php [L]
    # END WordPress
    
    #Domain Specific Redirects
    redirect 301 http://domainname.com/aboutus.html	http://domainname.com/our-history/

    but it didn’t work. Loading http://domainname.com/aboutus.html just brought up a 404 page.

    @ipstenu – thanks. It is a subfolder multisite install with the Domain Mapping plugin.

    Would love to do something dynamic on this whereas
    http://domainname.com/(*).html redirected to http://domainname.com/$1/

    I’m not sure where to place it in .htaccess so that it a) catches the domain mapping still and b) redirects the page if matched.

    Thanks in advance.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    http://domainname.com/(*).html redirected to http://domainname.com/$1/

    Easy peasy. Should be this:

    #Domain Specific Redirects
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com [NC]
    RewriteRule ^(.*).html$ http://domain.com/$1 [R=301,L]
    
    # BEGIN WordPress
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    
    # uploaded files
    RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
    
    # add a trailing slash to /wp-admin
    RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
    
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^ - [L]
    RewriteRule  ^[_0-9a-zA-Z-]+/(wp-(content|admin|includes).*) $1 [L]
    RewriteRule  ^[_0-9a-zA-Z-]+/(.*\.php)$ $1 [L]
    RewriteRule . index.php [L]
    # END WordPress

    Two points for your education 🙂

    1) ALWAYS put the redirects for stuff ABOVE the WordPress calls. That way you only process the WordPress stuff after you get the right URL. Saves redundancy

    2) Your WordPress calls were the older, less efficient sort. Still worked for most people, but we may as well clean ’em up.

    great stuff thx. mobile now but will try in the next hour. thanks for pointing out the cleanup!

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    Shirley.

    I’ll caveat that this

    #Domain Specific Redirects
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com [NC]
    RewriteRule ^(.*).html$ http://domain.com/$1 [R=301,L]

    may need some wiggling around :/ Every server is JUST enough different that you have to fuss and find the right one for you. Google’s a champ for examples on it 🙂

    Works like a charm and makes perfect sense, thanks. And don’t call me Shirley 😉

    That takes care of 50-ish standardized redirects.

    When I try to then add an additional rewrite for non-conforming pages:

    #Domain Specific Redirects
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^(www\.)?domainname\.com [NC]
    RewriteRule ^aboutus.html$ http://domainname.com/our-history [R=301]
    RewriteRule ^(.*).html$ http://domainname.com/$1 [R=301,L]

    a few things happen.

    First, rule #2 still works, but now it works regardless of the domain (losing the RewriteCond??) and second, rule #1 does not redirect, just fires up a 404.

    Arggg….I’ll keep Googlin, but if you see anything I am missing, I appreciate it.

    After dropping rule #1, I’m still getting the rule #2 regardless of domain. Now I’m spinning…going to clear my head, clear cache and try again.

    Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    🏳️‍🌈 Advisor and Activist

    Try this? Maybe it’s the www bit that’s confusing it?

    #Domain Specific Redirects
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www.domainname.com$[OR]
    RewriteCond %{HTTP_HOST} ^domainname.com$
    RewriteRule ^(.*).html$ http://domainname.com/$1 [R=301,L]

    If that works, we can try with the aboutus thing again.

    I’d love to hear about the correct syntax for page-specific redirects per the #1 / “aboutus” item above. I have the same need.

Viewing 15 replies - 1 through 15 (of 15 total)
  • The topic ‘.htaccess 301 redirection for multisite’ is closed to new replies.