Search code examples
apachemod-proxy

Apache configurations to restrict requests with specific string in request URL


I have one URL configured on Apache. Here is configuration

<VirtualHost 192.168.1.82:443>
        ServerName test.ex.com
        Header always set Strict-transport-Security "max-age=63072000; includeSubDomain; preload"
        Header always append X-Frame-Options SAMEORIGIN
        Header set X-XSS-Protection: "1; mode=block"
        ProxyRequests On

        ProxyPass /cong http://192.168.4.185:8081/cong
        ProxyPassReverse /cong http://192.168.4.185:8081/cong

        ErrorLog logs/test.ex.com-error_log
        CustomLog logs/test.ex.com-access_log common
        SSLEngine on
        SSLCertificateFile /etc/httpd/*.ex.com/36287365__.ex.com.cert
        SSLCertificateKeyFile /etc/httpd/*.ex.com/36287365__.ex.com.key
        Header add P3P "CP=\"NOI DSP COR CURa ADMa DEVa OUR IND OTC\""
</VirtualHost>

With above configurations, I am allowing all the request comes to https://test.ex.com/cong/. I want to restrict some specific request comes with string "getUserPattern" in request string like https://test.ex.com/cong/module/getUserPattern/final

Tried with ProxyBlock getUserPattern but didn't work. Is there any way/configuration to restrict such URLs at apache level only or redirect to https://test.ex.com/cong.


Solution

  • First, you probably want to disable forward (standard) proxy requests (Setting ProxyRequests to Off does not disable use of the ProxyPass directive):

    ProxyRequests Off
    

    If you want to redirect any request containing getUserPattern to https://test.ex.com/cong, add these two directives above your current ProxyPass rules:

    RedirectMatch "getUserPattern" "https://test.ex.com/cong"
    ProxyPassMatch "getUserPattern" !