Reverse proxy and .htaccess rewrite rules

We’ve created a reverse proxy on the main website which points to the sub-domain (WordPress instalation on a different server).

The main site is using CloudFlare.

I’ve tried these rewrite rules:

    RewriteCond %{HTTP:X-Forwarded-Host} !^$
    RewriteCond %{HTTP_HOST} ^blog\.example\.com$ [NC]
    RewriteRule (.*)$1 [R=301,L]
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^blog\.example\.com\$ [NC]  
    RewriteCond %{REQUEST_URI} ^/blog/ [NC]
    RewriteCond %{HTTP:X-Forwarded-Port} !=443
    RewriteRule ^(.*)$ blog/$1 [L,R=301,QSA]
    RewriteRule ^blog\/?(.*)$ "https\:\/\/example\.com\/$1" [R=301,L]
    RewriteCond %{HTTP_X_PROXY} "example"
    RewriteCond %{HTTP:X-Forwarded-Host} ^$
    RewriteCond %{HTTP_HOST} ^blog\.example\.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www\.blog\.example\.com$
    RewriteRule ^(.*)$ "https\:\/\/example\.com\/blog$1" [R=301,L]

In the last example, our developer added a “X-Proxy” with value “example” in the header.

None of those worked…

I talked to our hosting support, and they couldn’t figure it out either. They said that It does appear that CloudFlare may be preventing this redirect.

    HTTP/2 301 
    date: Wed, 04 Nov 2020 17:35:39 GMT
    content-type: text/html; charset=iso-8859-1
    cache-control: max-age=0
    expires: Wed, 04 Nov 2020 17:35:39 GMT
    cf-cache-status: DYNAMIC
    cf-request-id: 06245ed2b6c00018e1996976000000001
    expect-ct: max-age=604800, report-uri=""
    strict-transport-security: max-age=2592000
    server: cloudflare
    cf-ray: 5ed014bf12305e18-DTW

Any ideas what I can do to make this redirect work? It’s not a good idea to have both URLs accessible…

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.