1

I define a rewrite rule on an init hook like:

add_rewrite_rule( 'foobar/(abc|def|ghi)/(.+)(/(\d.+))', 'index.php?my_action=$matches[1]&my_name=$matches[2]&my_version=$matches[4]', 'top');

This works with following URL on a single WP installation:

http://example.com/foobar/def/whatever/1.2

However it doesn't on a multisite installation.

It seems there's problem with rewrite rules on multisite an there's ticket #19896 which describes a similar problem on "non WP rules"

I have no idea what I should add to the .htaccess file and I prefer a "proper" solution.

EDIT:

I have forget something important:

I'm using WordPress MU Domain Mapping to use different domains and while the network is on network.example.com the site I use add_rewrite_rule is sub.example.com

4
  • Since you rewrite to index.php it should work. Did you flush your rules?
    – Z. Zlatev
    Commented Sep 20, 2014 at 14:36
  • about 10 times ;)
    – Xaver
    Commented Sep 20, 2014 at 14:56
  • you don't have a non-wp rule, because you're pointing it to index.php. are you certain this works on a single installation? your query string doesn't contain any native query vars, so it can't generate a main query and will 404, the behavior you see is completely expected.
    – Milo
    Commented Sep 20, 2014 at 16:07
  • Yes, that ticket definitely does not apply to you. Rewrite rules that start with index.php are WP rules and don't modify the .htaccess file.
    – Otto
    Commented Sep 20, 2014 at 18:38

1 Answer 1

1

It seems the problem is not with add_rewrite_rule rather with the .htaccessfile for the multi site.

One of the test addresses was

http://example.com/foobar/def/whatever.php

Here's a part of the htaccess which causes the result (Line 2)

RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]

If I comment this line out it works as expected but it may break other thing. So you have to add your own rule above the latest block:

RewriteRule ^([_0-9a-zA-Z-]+/)?foobar/(abc|def|ghi)/(.+)(/(\d.+))$ index.php?my_action=$2&my_name=$3&my_version=$5 [R=301,L]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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