WordPress.org

Ready to get started?Download WordPress

Forums

.htaccess 301 redirection for multisite (16 posts)

  1. arnoldshields
    Member
    Posted 3 years ago #

    I am looking to convert a number of clients static sites to my wordpress multisite.

    How do you use .htaccess to 301 redirect multiple domains old pages to their new pages in multisite wordpress?

    ie.
    http://www.site1.com/Page1.html to http://www.site1.com/page1/
    http://www.site2.com/contact.html to http://www.site2.com/contact/

    or is it as simple as:

    Redirect 301 http://www.site1.com/Page1.html http://www.site1.com/page1/

  2. Or set up the wordpress permalinks with .html at the end? (yes, you can do that)

  3. arnoldshields
    Member
    Posted 3 years ago #

    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.

  4. headway
    Member
    Posted 3 years ago #

    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.

  5. 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

  6. ddarby14
    Member
    Posted 3 years ago #

    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.

  7. 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?

  8. 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.

  9. ddarby14
    Member
    Posted 3 years ago #

    @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.

  10. 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.

  11. ddarby14
    Member
    Posted 3 years ago #

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

  12. 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 :)

  13. ddarby14
    Member
    Posted 3 years ago #

    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.

  14. ddarby14
    Member
    Posted 3 years ago #

    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.

  15. 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.

  16. kirkvan
    Member
    Posted 3 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.