I am running a WordPress network. This means there are multiple websites produced by one installation of WordPress. Each website is a subdomain of the parent website. WordPress handles the creation of subdomain websites through a wildcard subdomain entered into cPanel, which points /public_html, which is where WordPress lives.

This means there is one .htaccess file serving all subdomain sites.

My parent website is www.doig.com.au. My problem website is tech.doig.com.au.

I need to 301 redirect http://tech.doig.com.au/venom-media.html to http://tech.doig.com.au/portfolio/venom-media/.

Previously, I had the following in my .htaccess file:

RewriteCond %{HTTP_HOST} ^tech\.doig\.com\.au$ [NC]
RewriteRule . - [S=120]
RewriteRule ^venom-media.html http://tech.doig.com.au/venom-media/ [R=301]
RewriteRule ^services.html/feed http://tech.doig.com.au/services/feed [L,R=301]

However, this no longer works.

This is my .htaccess file.

Why is the RewriteRule not working?

closed as off-topic by Stephen Ostermiller Dec 15 '13 at 10:55

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question appears to be off-topic because it is unlikely to help anybody else. Examples include individual website reviews for SEO purposes and general website troubleshooting." – Stephen Ostermiller
If this question can be reworded to fit the rules in the help center, please edit the question.

RewriteCond %{HTTP_HOST} ^tech\.doig\.com\.au$ [NC]
RewriteRule . - [S=120]

You appear to be Skipping all of the relevant redirects when the HOST matches tech.doig.com.au, which would seem to be the opposite of what you are trying to achieve. As it stands, your redirect would only occur when the domain is not tech.doig.com.au.

It looks like your RewriteCond directive should be negated:

RewriteCond %{HTTP_HOST} !^tech\.doig\.com\.au$ [NC]

The same is also true for another domain block in your .htaccess file, however, several rules in that section redirect to the other domain so I'm not sure what the intention is with that one.

For example:

## SUB DOMAIN: sub1
# If the HOST is NOT sub1 (note the negated (!) condition)
# then SKIP the next 120 rules that apply only to sub1
RewriteCond %{HTTP_HOST} !^sub1\.example\.com$ [NC]
RewriteRule . - [S=120]

# These rules will only apply when we are at sub1,
# since they would have been skipped otherwise
RewriteRule ^page1.html http://sub1.example.com/path/page1.html [R=301,L]
RewriteRule ^page2.html http://sub1.example.com/path/page2.html [R=301,L]
RewriteRule ^page120.html http://sub1.example.com/path/page120.html [R=301,L]

## SUB DOMAIN: sub2
# If the HOST is NOT sub2 then skip the next 40 rules
RewriteCond %{HTTP_HOST} !^sub2\.example\.com$ [NC]
RewriteRule . - [S=40]

# These rules will only apply when we are at sub2,
RewriteRule ^page1.html http://sub2.example.com/path/page1.html [R=301,L]
RewriteRule ^page2.html http://sub2.example.com/path/page2.html [R=301,L]
RewriteRule ^page40.html http://sub2.example.com/path/page40.html [R=301,L]

EDIT: The above still applies, however, you also have this block near the start of your .htaccess file which is possibly preventing all of your redirects from being actioned.

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule . index.php [L]

That 2nd RewriteRule appears to unconditionally rewrite all requests (other than the root) to index.php.

  • I removed the line that skips the rules, so they are no longer skipped, but the issue remains. – Steve Dec 12 '13 at 6:16
  • I've just noticed, what looks like, an unconditional rewrite near the top of your .htaccess file. I've updated my answer. – MrWhite Dec 12 '13 at 9:18
  • Those rules are Wordpress rules. I think they are correct. – Steve Dec 13 '13 at 9:53
  • They might be correct, but with them being at the top of your htaccess file they are essentially blocking all your other redirects. Your redirects should appear earlier in your htaccess file. – MrWhite Dec 13 '13 at 10:02
  • I moved those rules down to the bottom, but the URLs I'm trying to rewrite [301] are not being caught. I've updated .htaccess in pastebin. This website is a subdomain. Wordpress is installed on parent domain. This website is generated by Wordpress using wildcard subdomains set in cPanel. The only way I can redirect URLs on the subdomain is to use the parent domain's .htaccess, and set a rewrite condition RewriteCond %{HTTP_HOST} ^tech\.doig\.com\.au$ [NC]. – Steve Dec 13 '13 at 11:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.