Cloudflare 421 Misdirected Request when proxying API requests

What is the name of the domain?

demo.brenqo.io

What is the error number?

421

What is the error message?

Misdirected Request

What is the issue you’re encountering

Cloudflare 421 Misdirected Request when proxying API requests

Was the site working with SSL prior to adding it to Cloudflare?

Yes

What is the current SSL/TLS setting?

Full

What are the steps to reproduce the issue?

https://kababjees.brenqo.io/api/GetTokens when i hit this url it get’s data from: https://console.brenqo.com/api/GetTokens but same thing when i run from : https://demo.brenqo.io/api/GetTokens it returns: 421 Misdirected Request cloudflare

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Enable Proxy
    RewriteOptions Inherit
    Options +FollowSymLinks

    # Handle OPTIONS preflight requests first
    RewriteCond %{REQUEST_METHOD} OPTIONS
    RewriteRule .* - [R=200,L]

    # Proxy API requests
    RewriteCond %{REQUEST_URI} ^/api [NC,OR]
    RewriteCond %{REQUEST_URI} ^/ajax [NC,OR]
    RewriteCond %{REQUEST_URI} ^/upload [NC]
    RewriteRule ^(api|ajax|upload)(.*)$ https://console.brenqo.com/$1$2 [P,L,QSA]

    # Handle React routing
    RewriteBase /
    RewriteRule ^index\.html$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.html [L,QSA]
</IfModule>

# Set CORS and Proxy headers
<IfModule mod_headers.c>
    Header always set Access-Control-Allow-Origin "https://demo.brenqo.io"
    Header always set Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"
    Header always set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept, Authorization, X-CSRF-Token, X-Session-Token"
    Header always set Access-Control-Allow-Credentials "true"

    # Proxy Headers
    RequestHeader set Host "console.brenqo.com"
    RequestHeader set X-Forwarded-Host "console.brenqo.com"
    RequestHeader set X-Forwarded-Proto "https"
    RequestHeader set X-Forwarded-For %{REMOTE_ADDR}e
</IfModule>

# Enable required modules
<IfModule !mod_ssl.c>
    Error "mod_ssl is not installed or loaded"
</IfModule>

<IfModule !mod_proxy.c>
    Error "mod_proxy is not installed or loaded"
</IfModule>

<IfModule !mod_proxy_http.c>
    Error "mod_proxy_http is not installed or loaded"
</IfModule>

# Enable SSL Proxying for Cloudflare
SSLProxyEngine On
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerExpire off

# Proxy Settings
ProxyPreserveHost On
ProxyPass /api https://console.brenqo.com/api retry=0 connectiontimeout=5 timeout=60
ProxyPassReverse /api https://console.brenqo.com/api
ProxyPass /ajax https://console.brenqo.com/ajax retry=0 connectiontimeout=5 timeout=60
ProxyPassReverse /ajax https://console.brenqo.com/ajax

this is the htaccess that i’m using for both
demo.brenqo.io
and kababjees.brenqo.io

1 Like

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