WordPress comment post redirects not correctly rewritten

I’m using URL Rewrite / ARR as reverse proxy to simulate a WordPress installation in an IIS subdirectory which is actually running on a remote Apache.

It is working better than I’d expected, but there is one annoying problem left: When a user posts a comment it is correctly redirected and saved at the wp side. However, the following redirect doesn’t get rewritten correctly:
I’m getting e.g. http://domain.tld/2014/01/11/posttitle/#comment-6 instead of http://domain.tld/blog/2014/01/11/posttitle/#comment-6.
As I said before, all other relevant links/images/stylesheets are working as expected and are rewritten to domain.tld/blog/<path>.

Read More

The last operation on WordPress side seems to be (in wp-comments-post.php):

$location = apply_filters( 'comment_post_redirect', $location, $comment );
wp_safe_redirect( $location );

Here are my rewrite rules:

<rewrite>
    <rules>
    <rule name="RewriteRemoteAddr">
            <match url="(.*)" />
            <conditions>
                <add input="{HTTP_X_FORWARDED_FOR}" pattern="([_0-9a-zA-Z]+)" />
            </conditions>
            <serverVariables>
                <set name="{REMOTE_ADDR}" value="{HTTP_X_FORWARDED_FOR}" />
            </serverVariables>
            <action type="None" />
        </rule>
        <rule name="ReverseProxyInboundRule1" stopProcessing="true">
            <match url="(.*)" />
            <conditions>
                <add input="{CACHE_URL}" pattern="^(https?)://" />
            </conditions>
            <action type="Rewrite" url="{C:1}://blog.domain.tld/{R:1}" />
        </rule>
    </rules>
    <outboundRules>
        <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
            <match filterByTags="A, Form, Img" pattern="^http(s)?://blog.domain.tld/(.*)" />
            <action type="Rewrite" value="http{R:1}://domain.tld/blog/{R:2}" />
        </rule>
        <preConditions>
            <preCondition name="ResponseIsHtml1">
                <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
            </preCondition>
        </preConditions>
    </outboundRules>
</rewrite>

System:
IIS 8.5, URL Rewrite 2, ARR 3
Wordpress 3.8

EDIT W3SVC9 log entries:

2014-01-11 19:12:14 W3SVC9 ares 444.444.444.444 POST /blog/wp-comments-post.php X-ARR-CACHE-HIT=0&X-ARR-LOG-ID=d6339e31-547d-4f25-b1cc-5ebe2b485a1d 443 - 333.333.333.333 HTTP/1.1 Mozilla/5.0+(Windows+NT+6.3;+WOW64;+rv:26.0)+Gecko/20100101+Firefox/26.0 comment_author_b9276ad9dc2bc4f28d3a0f251eafa31e=tester;+comment_author_email_b9276ad9dc2bc4f28d3a0f251eafa31e=test%40example.com;+wordpress_test_cookie=WP+Cookie+check https://domain.tld/blog/2013/12/27/posttitle/ blog.domain.tld 302 0 0 906 1283 156
2014-01-11 19:12:14 W3SVC9 ares 444.444.444.444 GET /2013/12/27/posttitle/ - 443 - 333.333.333.333 HTTP/1.1 Mozilla/5.0+(Windows+NT+6.3;+WOW64;+rv:26.0)+Gecko/20100101+Firefox/26.0 comment_author_b9276ad9dc2bc4f28d3a0f251eafa31e=tester;+comment_author_email_b9276ad9dc2bc4f28d3a0f251eafa31e=test%40example.com;+wordpress_test_cookie=WP+Cookie+check https://domain.tld/blog/2013/12/27/posttitle/ domain.tld 404 0 0 6282 926 171

Thanks!

Related posts

Leave a Reply