-2

We have a rewrite rule for categories at archive site in .htaccess file on our server. This is a wordpress site. I am using iTheme Security plugin and at times this plugin meddles with the .htaccess file.

RewriteCond %{REQUEST_URI} ^/(apple|ball|cat)
RewriteRule ^ http://archive.domain.com%{REQUEST_URI} [R=301,L]

Here apple, ball and cat are the categories from old site which we have now on archive.domain.com . So anybody who finds a old link with domain.com/apple/1234 is redirected to archive.domain.com/apple/1234 .

This was working fine. Recently we hosted the same site on another server for 3/4 days and got back to the same server with everything same including .htaccess file where above code lies. And now its not working.

Not sure what changed.

Update: I have noticed another thing which might be issue in blocking the redirects.

domain.com/apple/1234 (if doesn't exist) is going to domain.com/random/1234 if exists. So if I am trying to redirect domain.com/apple/123 to archive.domain.com/123 the redirect is not working because other redirect match is taking over it.

  • other redirects from same .htaccess file is working fine. – Chandan Gupta Oct 10 '17 at 10:11
  • Please include the rest of your .htaccess file. There is nothing wrong with the directives you've posted, but it's taken out of context. Context is everything when it comes to .htaccess. – MrWhite Oct 10 '17 at 10:29
  • sorry, but I do not see anything wordpress specific here – Mark Kaplun Oct 10 '17 at 10:38
  • @MrWhite full htaccess is very very long as various plugins (including w3 total cache etc) has added their own configs. I will try to get the htaccess somewhere and post the link here. – Chandan Gupta Oct 10 '17 at 10:59
  • @mark-kaplun : Sometimes security plugins block some of the htaccess rewrite rules. Since I had no idea why this suddenly stopped working just because we changed server for few days. I had/have doubt that some or the other plugin might be meddling with htaccess. Therefore I posted here in wordpress forum. Thanks. – Chandan Gupta Oct 10 '17 at 11:01
0

What is the RewriteBase set to? Is this the first rewrite rule in the .htaccess?

Why are you doing it with a RewriteCond instead of directly going for

RewriteRule ^/(apple|ball|cat)(.*) http://archive.domain.com/$1$2 [R=301,L]

(Change ^/ to ^ if You have RewriteBase / in effect)?

  • 2
    RewriteBase is irrelevant here. RewriteBase only affects relative paths in the RewriteRule substitution - not the pattern. ^/ at the start of the RewriteRule pattern would only work if this was used directly in the server config (or virtual host) context. In .htaccess you will need to use just ^. – MrWhite Oct 10 '17 at 10:35
  • 2
    Ah, thanks. I've gotten so used to always set RewriteBase / and start with ^ without / and haven't actually questioned why. #LearnSomethingEveryday – janh Oct 10 '17 at 10:39
  • (This contrasts with the REQUEST_URI server variable, which always starts with a slash.) – MrWhite Oct 10 '17 at 10:43
  • @janh2 this id not work. – Chandan Gupta Oct 10 '17 at 17:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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