0

I am having an issue that is very similar to the one described here, which was never resolved.

I have a WordPress Multisite install with subdomains and I'm trying to get the old URLs to redirect to the new ones.

Basically, I'm using

RewriteCond %{HTTP_HOST}

to target each subdomain, with a batch of RewriteRules following.

Here is a small snippet of my code:

# Rewrite rules for French site
RewriteCond %{HTTP_HOST} ^fr.nomacorc.com$ [nc]
RewriteRule ^home\.php$ http://fr.nomacorc.com/ [R=301,NC,L]
RewriteRule ^aboutus\.php$ http://fr.nomacorc.com/propos-de-nous/ [R=301,NC,L]
RewriteRule ^ourclosures\.php$ http://fr.nomacorc.com/bouchons-pour-le-vin/ [R=301,NC,L]

# Rewrite rules for German site
RewriteCond %{HTTP_HOST} ^de.nomacorc.com$ [nc]
RewriteRule ^home\.php$ http://de.nomacorc.com/ [R=301,NC,L]
RewriteRule ^aboutus\.php$ http://de.nomacorc.com/uber-uns/ [R=301,NC,L]
RewriteRule ^ourclosures\.php$ http://de.nomacorc.com/weinverschlusse/ [R=301,NC,L]

What I want to have happen is for de.nomacorc.com/aboutus.php to redirect to de.nomacorc.com/uber-uns, but instead it's redirecting to fr.nomacorc.com/propos-de-nous/. Same thing is happening with the ourclosures.php redirect.

What am I doing wrong with this code?

Community
  • 1
  • 1
isabisa
  • 649
  • 2
  • 10
  • 23

1 Answers1

3

I found the answer on this other thread.

What I needed to do was link the group of RewriteRules to the above RewriteCond. The way to do that was describes really well:

- Negate the condition (prepend it with !)
- If you have multiple RewriteConds:
- Change logical ANDs in the Conds to ORs and vice versa.
- Add a skipping rewrite rule in front of all rules that you want to tie to the condition(s), set the S parameter to the number of Rule lines to be skipped.

So here is my corrected code:

# Rewrite rules for French site
RewriteCond %{HTTP_HOST} !^fr.nomacorc.com$ [nc]
RewriteRule .? - [S=3]
RewriteRule ^home\.php$ http://fr.nomacorc.com/ [R=301,NC,L]
RewriteRule ^aboutus\.php$ http://fr.nomacorc.com/propos-de-nous/ [R=301,NC,L]
RewriteRule ^ourclosures\.php$ http://fr.nomacorc.com/bouchons-pour-le-vin/ [R=301,NC,L]

# Rewrite rules for German site
RewriteCond %{HTTP_HOST} !^de.nomacorc.com$ [nc]
RewriteRule .? - [S=3]
RewriteRule ^home\.php$ http://de.nomacorc.com/ [R=301,NC,L]
RewriteRule ^aboutus\.php$ http://de.nomacorc.com/uber-uns/ [R=301,NC,L]
RewriteRule ^ourclosures\.php$ http://de.nomacorc.com/weinverschlusse/ [R=301,NC,L]

I hope this helps anyone else who may have the same problem!

Community
  • 1
  • 1
isabisa
  • 649
  • 2
  • 10
  • 23