301 redirects on Multisite

So this is picking up from here but the issue is the same.

I'm using RewriteCond %{HTTP_HOST} to target different domains in a multisite install with RewriteRule for the 301s of each url for that specific domain.

Here's my code:

RewriteEngine On
RewriteBase /

# Blog ID1 Rewrite Rules
RewriteCond %{HTTP_HOST} ^primary-domain.co.uk$ [nc]
RewriteRule ^about/careers/$ ^contact/careers/ [R=301,NC,L]
RewriteRule ^glossary.html$ ^sitemap/ [R=301,NC,L]

# Blog ID3 Rewrite Rules
RewriteCond %{HTTP_HOST} ^mapped-domain3.co.uk$ [nc]
RewriteRule ^about/$ http://mapped-domain2.co.uk/about/ [R=301,NC,L]
RewriteRule ^news/$ http://mapped-domain2.co.uk/news/ [R=301,NC,L]

If a page exists on one domain that's being redirected on another, the redirect still takes effect. For example:

http://mapped-domain3.co.uk/about/ is being redirected as above.
http://primary-domain.co.uk/about/ exists also and I do not want this redirected.
With my code above both pages from both domains are being redirected to http://mapped-domain2.co.uk/about/

Where am I going wrong.?

  • Tom Eagles

    @Jonny Wood

    The regex looks fine to me I am not sure why that isnt working :slight_frown: , @Timothy is one of our regex masters so i am going to tag him and also grab him when he gets online to talk this over with him and get staright back to you,

    I have included a link to the wordpress codex on this just for reference here

    http://codex.wordpress.org/Rewrite_API/add_rewrite_rule

    Cheers

    Tom

  • Jonny Wood

    Okay, the live site can be found here.

    htaccess is as follows:

    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTP_HOST} ^cy4or\.co\.uk$ [NC]
    
    # cy4or.co.uk 302 > 301
    RewriteRule ^feed/atom/$ http://feeds.feedburner.com/CY4OR [R=301,NC,L]
    RewriteRule ^contact/$ ^contact/form/ [R=301,NC,L]
    RewriteRule ^about/$ ^about/about-us/ [R=301,NC,L]
    RewriteRule ^experience/$ ^about/experience/our-work/ [R=301,NC,L]
    
    # cy4or.co.uk Rewrite Rules (pre 2012)
    RewriteRule ^div$ / [R=301,NC,L]
    RewriteRule ^div/$ / [R=301,NC,L]
    RewriteRule ^about/careers/$ ^contact/careers/ [R=301,NC,L]
    RewriteRule ^forensic-services/computer-forensics/$ ^services/digital-forensics/computer-forensics/ [R=301,NC,L]
    RewriteRule ^forensic-services/edisclosure/$ ^services/edisclosure/ [R=301,NC,L]
    RewriteRule ^forensic-services/data-collection/$ ^services/digital-forensics/onsite-investigation/ [R=301,NC,L]
    RewriteRule ^forensic-services/mobile-device-forensics/$ ^services/digital-forensics/mobile-device-forensics/ [R=301,NC,L]
    RewriteRule ^forensic-services/cell-site-analysis/$ ^services/digital-forensics/cell-site-analysis/ [R=301,NC,L]
    RewriteRule ^forensic-services/audio-video-forensics/$ ^services/digital-forensics/audio-video-forensics/ [R=301,NC,L]
    RewriteRule ^forensic-services/incident-response/$ ^services/digital-forensics/onsite-investigation/ [R=301,NC,L]
    RewriteRule ^services/digital-forensics/data-recovery/$ ^services/digital-forensics/onsite-investigation/ [R=301,NC,L]
    RewriteRule ^forensic-services/vulnerability-assessment/$ ^services/information-security/ [R=301,NC,L]
    RewriteRule ^forensic-services/forensic-readiness-planning/$ ^services/digital-forensics/forensic-readiness-planning/ [R=301,NC,L]
    RewriteRule ^forensic-services/data-recovery-destruction/$ ^services/digital-forensics/onsite-investigation/ [R=301,NC,L]
    RewriteRule ^market-sectors/legal-professional/$ ^sectors/legal-professional/ [R=301,NC,L]
    RewriteRule ^market-sectors/regulatory-and-law-enforcement/$ ^sectors/regulatory-law-enforcement/ [R=301,NC,L]
    RewriteRule ^market-sectors/public-sector/$ ^sectors/public/ [R=301,NC,L]
    RewriteRule ^market-sectors/private-sector/$ ^sectors/private/ [R=301,NC,L]
    RewriteRule ^contact-us/$ ^contact/form/ [R=301,NC,L]
    RewriteRule ^glossary.html/$ ^sitemap/ [R=301,NC,L]
    
    # cy4or.co.uk 404s
    RewriteRule ^news/nobody-seems-to-give-a-seconds-thought-to-data-recovery-until-its-too-late-cy4ors-information-security-specialist-shaun-peapell-shares-his-experiences/$ news/ [R=301,NC,L]
    RewriteRule ^news/cpd-accredited-edisclosure-seminar/$ ^news/events/cpd-accredited-edisclosure-seminar/ [R=301,NC,L]
    RewriteRule ^resources/data-sheets/clearwell-digital-investigations-solution-the-challenge-more-digital-investigations-more-email-and-documents-but-no-more-time/$ ^resources/data-sheets/clearwell-digital-investigations-solution/ [R=301,NC,L]
    RewriteRule ^resources/white-papers/understanding-the-impact-of-early-case-assessment-to-your-organisation/$ ^resources/white-papers/early-case-assessment-to-your-organisation/ [R=301,NC,L]
    RewriteRule ^contact/contact-thanks/$ ^contact/thanks/ [R=301,NC,L]
    RewriteRule ^resources/data-sheets/clearwell-datasheet-legal-hold-module/$ ^resources/datasheets/clearwell-legal-hold-solution/ [R=301,NC,L]
    RewriteRule ^resources/white-papers/proving-defensibility/$ ^resources/white-papers/proving-the-defensibility-of-phonetic-audio-search-in-civil-discovery/ [R=301,NC,L]
    RewriteRule ^resources/white-papers/nexidia-phonetic-search/$ ^resources/white-papers/phonetic-search-technology/ [R=301,NC,L]
    
    # ediscovery.co.uk Rewrite Rules
    RewriteCond %{HTTP_HOST} ^ediscovery\.co\.uk$ [NC]
    RewriteRule ^div$ / [R=301,NC,L]
    RewriteRule ^div/$ / [R=301,NC,L]
    RewriteRule ^contact/details/$ ^contact/form/ [R=301,NC,L]
    RewriteRule ^clearwell-legal-edisclosure-solution-3/$ ^solutions/legal-professional/ [R=301,NC,L]
    RewriteRule ^/news/events/the-importance-of-electronic-evidence/$ http://cy4or.co.uk/news/events/past-events/the-importance-of-electronic-evidence/ [R=301,NC,L]
    
    # BEGIN WordPress
    RewriteRule ^wp-admin - [L]
    RewriteRule ^index\.php$ - [L]
    
    # uploaded files
    RewriteRule ^([_0-9a-zA-Z-]+/)?files/(.+) wp-includes/ms-files.php?file=$2 [L]
    
    RewriteRule ^(.*/)?sitemap.xml wp-content/sitemap.php [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

    I really hope there's something wrong there, otherwise I have no idea how to resolve this!

  • Vaughan

    hiya

    we could try instead using the full url in the rules

    instead of

    RewriteCond %{HTTP_HOST} ^primary-domain.co.uk$ [nc]
    RewriteRule ^about/careers/$ ^contact/careers/ [R=301,NC,L]
    RewriteRule ^glossary.html$ ^sitemap/ [R=301,NC,L]

    try

    RewriteCond %{HTTP_HOST} ^primary-domain.co.uk$ [nc]
    RewriteRule ^primary-domain.co.uk/about/careers/$ ^primary-domain.co.uk/contact/careers/ [R=301,NC,L]
    RewriteRule ^primary-domain.co.uk/glossary.html$ ^primary-domain.co.uk/sitemap/ [R=301,NC,L]

    also what might be worth a try.

    in wp-config.php

    try changing Domain current site define to

    define(‘DOMAIN_CURRENT_SITE’, $_SERVER['HTTP_HOST']);

    it might also be worth trying to comment out the follwoing lines too if the above doesn't work.

    //define(‘DOMAIN_CURRENT_SITE’, ‘blogs.example.com’);
    //define(‘PATH_CURRENT_SITE’, ‘/’);
    //define(‘SITE_ID_CURRENT_SITE’, 1);
    //define(‘BLOG_ID_CURRENT_SITE’, 1);

    hope this helps.

  • cuberis

    I know this was posted a long time ago, but hopefully this will help others searching for the answer.

    I had this same problem and did some research into it. It looks like the RewriteRules all need to be linked to the above RewriteCond. Here is the code that worked for me.

    So a short example of yours would be:

    # Blog ID1 Rewrite Rules
    RewriteCond %{HTTP_HOST} !^primary-domain.co.uk$ [nc]
    RewriteRule .? - [S=2]
    RewriteRule ^about/careers/$ ^contact/careers/ [R=301,NC,L]
    RewriteRule ^glossary.html$ ^sitemap/ [R=301,NC,L]
    
    # Blog ID3 Rewrite Rules
    RewriteCond %{HTTP_HOST} !^mapped-domain3.co.uk$ [nc]
    RewriteRule .? - [S=2]
    RewriteRule ^about/$ http://mapped-domain2.co.uk/about/ [R=301,NC,L]
    RewriteRule ^news/$ http://mapped-domain2.co.uk/news/ [R=301,NC,L]

    Obviously, you'd need to change the number in the S flag to the number of rules below it that apply to the above RewriteCond.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.